Skip to content

Commit a6e729a

Browse files
committed
Mention problems with GIL and threads [ci skip]
1 parent 4bfdd2a commit a6e729a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,34 @@ computations or I/O at the moment. Sending SIGINT with
323323
For the update on this problem, see:
324324
https://github.com/JuliaPy/pyjulia/issues/211
325325

326+
### No threading support
327+
328+
PyJulia cannot be used in different threads since libjulia is not
329+
thread safe. However, you can
330+
[use thread within Julia](https://docs.julialang.org/en/v1.0/manual/parallel-computing/#Multi-Threading-(Experimental)-1).
331+
For example, start IPython by `JULIA_NUM_THREADS=4 ipython` and then
332+
run:
333+
334+
```julia
335+
In [1]: %load_ext julia.magic
336+
Initializing Julia interpreter. This may take some time...
337+
338+
In [2]: %%julia
339+
...: a = zeros(10)
340+
...: Threads.@threads for i = 1:10
341+
...: a[i] = Threads.threadid()
342+
...: end
343+
...: a
344+
Out[3]: array([1., 1., 1., 2., 2., 2., 3., 3., 4., 4.])
345+
```
346+
347+
### PyJulia does not release GIL
348+
349+
PyJulia (or rather PyCall) does not release GIL while calling Julia
350+
functions. It means that Python code and Julia code cannot run in
351+
parallel.
352+
353+
326354
Testing
327355
-------
328356

0 commit comments

Comments
 (0)