-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import deadlock with streams #193
Comments
Oh, the offending |
Here's a fine place for the issue for now. We can consider removing the eventloop wait in flush. I'll need to investigate what that is there for (I think it might have to do with forked subprocesses exiting before sending completes). |
It's there for the semantics, I think. |
Fixes ipython#193. This should make sure we properly cull all subprocesses at shutdown, it does change one of the private method from sync to async in order to no user time.sleep or thread so this may affect subclasses, though I doubt it. It's also not completely clear to me whether this works on windows as SIGINT I belove is not a thing. Regardless as this affects things like dask, and others that are mostly on unix, it should be an improvement. It does the following, stopping as soon as it does not find any more children to current process. - Send sigint to everything - Immediately send sigterm in look with an exponential backoff from 0.01 to 1 second roughtly multiplying the delay until next send by 3 each time. - Switch to sending sigkill with same backoff. There is no delay after sigint, as this is just a courtesy. The delays backoff are not configurable. I can imagine that on slow systems it may make sens
Write this text to the file
minimal.py
:Start up an IPython (Python 2; the issue may not exist in Python 3) notebook. Execute
import minimal
. The kernel will become unresponsive.The problem is that
sys.stdout.flush()
will call theOutputStream.flush()
method which adds a callback to the event loop that sends off azmq
message to the notebook. That callback is executed in another thread. To create the message to send, it will create a UUID usinguuid.uuid4()
which has a local import ofos
in it. Python 2 has a global import lock that was acquired by the main thread which is executing ourimport minimal
. That import does not complete becauseOutputStream.flush()
is synchronous and is waiting for the event loop to be processed. Deadlock.As far as I can tell, this is the only place that something is imported at runtime in the message-sending thread, so reimplementing
uuid.uuid4()
to not locally import would be a minimal fix that avoids the issue.The text was updated successfully, but these errors were encountered: