# Julia crashed when using PyCall in multiple threads

**URL:** <https://discourse.julialang.org/t/julia-crashed-when-using-pycall-in-multiple-threads/111004>\
**Category:** General Usage\
**Tags:** pycall\
**Created:** [March 1, 2024, 9:20am UTC](https://discourse.julialang.org/t/julia-crashed-when-using-pycall-in-multiple-threads/111004 "2024-03-01T09:20:44Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 1, 2024, 3:16pm UTC](https://discourse.julialang.org/t/julia-crashed-when-using-pycall-in-multiple-threads/111004/8 "2024-03-01T15:16:09Z")

</div>

> **[Writing reentrant and threadsafe code](https://www.ibm.com/docs/en/aix/7.2?topic=programming-writing-reentrant-threadsafe-code#writing_reentrant_thread_safe_code __title__ 9)**
>
> In single-threaded processes, only one flow of control exists. The code executed by these processes thus need not be reentrant or threadsafe. In multithreaded programs, the same functions and the same resources may be accessed concurrently by several...

It means you use a lock such that only one thread of your Julia program can access your Python call at any given time…

I did not try this yet, it might work, but it also might mean that you need a handler in the main thread that communicates with your other threads and calls Python…

---

_[View the full topic](https://discourse.julialang.org/t/julia-crashed-when-using-pycall-in-multiple-threads/111004)._
