Skip to content

JuliaCall: lock the GIL when the IPython extension copies Julia output - #851

Open
MilesCranmerBot wants to merge 1 commit into
JuliaPy:mainfrom
MilesCranmerBot:juliacall-ipython-gil
Open

MilesCranmerBot wants to merge 1 commit into
JuliaPy:mainfrom
MilesCranmerBot:juliacall-ipython-gil

Conversation

@MilesCranmerBot

Copy link
Copy Markdown
Contributor

Why

In Jupyter, the JuliaCall IPython extension copies Julia's stdout and stderr to Python from two background tasks. These tasks call Python without the GIL if Julia prints while the GIL is unlocked, for example in _jl_call_nogil, and the process segfaults. This is the first case in #542.

What changed

  • The copy tasks lock the GIL around each write to Python.

Scope

Verification

  • New test_ipython_output_nogil runs the extension with a kernel-like shell in a subprocess and prints from _jl_call_nogil. Without the fix the child segfaults (return code -11); with it, the output reaches Python's sys.stdout.

The same crash affects seval(..., nogil=True) from #850.

In Jupyter the extension copies Julia's stdout and stderr to Python from background
tasks. If Julia printed while the GIL was unlocked, for example in `_jl_call_nogil`,
those tasks called Python without the GIL and the process segfaulted (JuliaPy#542).

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant