Skip to content
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

Avoid setting event loop policy if within Jupyter notebook server #2343

Merged
merged 1 commit into from Nov 9, 2018

Conversation

mrocklin
Copy link
Member

@mrocklin mrocklin commented Nov 8, 2018

This is a hack.

If Dask is imported within the Jupyter notebook server it can cause the
server to hang. This occurs because Dask sets an asyncio event loop
policy useful when starting multiple event loops in multiple threads.
Unfortunately setting this policy after Jupyter has already created an
event loop causes Jupyter to have two different event loops, which
understandably causes difficulties.

In the future we should investigate avoiding setting global asyncio
policies, possibly through managing event loops ourselves without using
asyncio.get_event_loop but until then this special-cased hack should
relieve some pressure.

Note that this means that some advanced functionality, like
get_client, as_completed and so forth won't work. Fortunately these
are unlikely to be relevant within the Jupyter server process, which is
more likely to run scheduler rather than client code.

See jupyter/notebook#4183

This is a hack.

If Dask is imported within the Jupyter notebook server it can cause the
server to hang.  This occurs because Dask sets an asyncio event loop
policy useful when starting multiple event loops in multiple threads.
Unfortunately setting this policy after Jupyter has already created an
event loop causes Jupyter to have two different event loops, which
understandably causes difficulties.

In the future we should investigate avoiding setting global asyncio
policies, possibly through managing event loops ourselves without using
`asyncio.get_event_loop` but until then this special-cased hack should
relieve some pressure.

Note that this means that some advanced functionality, like
`get_client`, `as_completed` and so forth won't work.  Fortunately these
are unlikely to be relevant within the Jupyter server process, which is
more likely to run scheduler rather than client code.

See jupyter/notebook#4183
@ian-r-rose
Copy link
Collaborator

Looks good to me. Thanks for running this down @minrk and @mrocklin.

@mrocklin mrocklin merged commit ed48c08 into dask:master Nov 9, 2018
@mrocklin mrocklin deleted the jupyter-event-loop branch November 9, 2018 14:12
mrocklin pushed a commit that referenced this pull request Dec 31, 2019
…ng event loop (#3336)

Setting asyncio event loop policy at these two places could cause problems.
1. When policy is set in Jupyter notebook server extension.
This causes the notebook server to hang. This is fixed in #2343.
2. When policy is set in iPython startup config (`~/.ipython/profile_default/startup/whatever.py`) or by setting `get_config().InteractiveShellApp.exec_lines` in `~/.ipython/profile_default/ipython_config.py`.
This causes the kernel to hang. This can be reproduced by running either `jupyter console` or `jupyter notebook`. If running In Jupyter notebook, it will struck at "Kernel starting, please wait...".
Note that manually setting the policy in notebook cell, after the kernel has started, is fine.

In both cases, running `asyncio.get_running_loop()` just before setting the policy will raise `RuntimeError`, meaning there is no running event loop yet.

See #3202.
bnaul pushed a commit to replicahq/distributed that referenced this pull request Feb 10, 2020
…ng event loop (dask#3336)

Setting asyncio event loop policy at these two places could cause problems.
1. When policy is set in Jupyter notebook server extension.
This causes the notebook server to hang. This is fixed in dask#2343.
2. When policy is set in iPython startup config (`~/.ipython/profile_default/startup/whatever.py`) or by setting `get_config().InteractiveShellApp.exec_lines` in `~/.ipython/profile_default/ipython_config.py`.
This causes the kernel to hang. This can be reproduced by running either `jupyter console` or `jupyter notebook`. If running In Jupyter notebook, it will struck at "Kernel starting, please wait...".
Note that manually setting the policy in notebook cell, after the kernel has started, is fine.

In both cases, running `asyncio.get_running_loop()` just before setting the policy will raise `RuntimeError`, meaning there is no running event loop yet.

See dask#3202.
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.

None yet

3 participants