Skip to content

Trigger application of nest patch in set_event_loop_policy#189

Merged
sphuber merged 1 commit intodevelopfrom
fix/188/jupyter-event-loop
Dec 18, 2020
Merged

Trigger application of nest patch in set_event_loop_policy#189
sphuber merged 1 commit intodevelopfrom
fix/188/jupyter-event-loop

Conversation

@sphuber
Copy link
Copy Markdown
Collaborator

@sphuber sphuber commented Dec 17, 2020

Fixes #188

The PlumpyEventLoopPolicy is designed to apply the nest_asyncio
patch to the event loop to make it reentrant. Once the policy is applied
using set_event_loop_policy the idea is that when calling
asyncio.get_event_loop the get_event_loop of PlumpyEventLoopPolicy
is called instead which will apply the patch to the loop if not already
done before.

However, in a Jupyter notebook, asyncio.get_event_loop would not
actually call the patched get_event_loop of the policy, even do the
policy was set. This was proved by the fact that calling the method
asyncio.get_event_loop_policy would return PlumpyEventLoopPolicy. It
was not until asyncio.get_event_loop_policy().get_event_loop() was
called that the patch policy was called and the loop was patched.

As a workaround the set_event_loop_policy is updated to directly after
setting the new policy to call get_event_loop_policy. Through an
unknown mechanism, this forces that asyncio.get_event_loop will
actually start to call the implementation of the new policy.

@sphuber sphuber requested review from muhrin and unkcpz December 17, 2020 15:02
Copy link
Copy Markdown
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sphuber thanks! looks good to me.

The `PlumpyEventLoopPolicy` is designed to apply the `nest_asyncio`
patch to the event loop to make it reentrant. Once the policy is applied
using `set_event_loop_policy` the idea is that when calling
`asyncio.get_event_loop` the `get_event_loop` of `PlumpyEventLoopPolicy`
is called instead which will apply the patch to the loop if not already
done before.

However, in a Jupyter notebook, `asyncio.get_event_loop` would not
actually call the patched `get_event_loop` of the policy, even do the
policy was set. This was proved by the fact that calling the method
`asyncio.get_event_loop_policy` would return `PlumpyEventLoopPolicy`. It
was not until `asyncio.get_event_loop_policy().get_event_loop()` was
called that the patch policy was called and the loop was patched.

As a workaround the `set_event_loop_policy` is updated to directly after
setting the new policy to call `get_event_loop_policy`. Through an
unknown mechanism, this forces that `asyncio.get_event_loop` will
actually start to call the implementation of the new policy.
@sphuber sphuber force-pushed the fix/188/jupyter-event-loop branch from 678c073 to 32cfafc Compare December 18, 2020 09:42
@sphuber sphuber merged commit 0f18e66 into develop Dec 18, 2020
@sphuber sphuber deleted the fix/188/jupyter-event-loop branch December 18, 2020 09:48
unkcpz pushed a commit to unkcpz/plumpy that referenced this pull request Dec 14, 2024
…am#189)

The `PlumpyEventLoopPolicy` is designed to apply the `nest_asyncio`
patch to the event loop to make it reentrant. Once the policy is applied
using `set_event_loop_policy` the idea is that when calling
`asyncio.get_event_loop` the `get_event_loop` of `PlumpyEventLoopPolicy`
is called instead which will apply the patch to the loop if not already
done before.

However, in a Jupyter notebook, `asyncio.get_event_loop` would not
actually call the patched `get_event_loop` of the policy, even do the
policy was set. This was proved by the fact that calling the method
`asyncio.get_event_loop_policy` would return `PlumpyEventLoopPolicy`. It
was not until `asyncio.get_event_loop_policy().get_event_loop()` was
called that the patch policy was called and the loop was patched.

As a workaround the `set_event_loop_policy` is updated to directly after
setting the new policy to call `get_event_loop_policy`. Through an
unknown mechanism, this forces that `asyncio.get_event_loop` will
actually start to call the implementation of the new policy.
agoscinski pushed a commit to agoscinski/plumpy that referenced this pull request Apr 13, 2026
…am#189)

The `PlumpyEventLoopPolicy` is designed to apply the `nest_asyncio`
patch to the event loop to make it reentrant. Once the policy is applied
using `set_event_loop_policy` the idea is that when calling
`asyncio.get_event_loop` the `get_event_loop` of `PlumpyEventLoopPolicy`
is called instead which will apply the patch to the loop if not already
done before.

However, in a Jupyter notebook, `asyncio.get_event_loop` would not
actually call the patched `get_event_loop` of the policy, even do the
policy was set. This was proved by the fact that calling the method
`asyncio.get_event_loop_policy` would return `PlumpyEventLoopPolicy`. It
was not until `asyncio.get_event_loop_policy().get_event_loop()` was
called that the patch policy was called and the loop was patched.

As a workaround the `set_event_loop_policy` is updated to directly after
setting the new policy to call `get_event_loop_policy`. Through an
unknown mechanism, this forces that `asyncio.get_event_loop` will
actually start to call the implementation of the new policy.
agoscinski pushed a commit that referenced this pull request Apr 13, 2026
The `PlumpyEventLoopPolicy` is designed to apply the `nest_asyncio`
patch to the event loop to make it reentrant. Once the policy is applied
using `set_event_loop_policy` the idea is that when calling
`asyncio.get_event_loop` the `get_event_loop` of `PlumpyEventLoopPolicy`
is called instead which will apply the patch to the loop if not already
done before.

However, in a Jupyter notebook, `asyncio.get_event_loop` would not
actually call the patched `get_event_loop` of the policy, even do the
policy was set. This was proved by the fact that calling the method
`asyncio.get_event_loop_policy` would return `PlumpyEventLoopPolicy`. It
was not until `asyncio.get_event_loop_policy().get_event_loop()` was
called that the patch policy was called and the loop was patched.

As a workaround the `set_event_loop_policy` is updated to directly after
setting the new policy to call `get_event_loop_policy`. Through an
unknown mechanism, this forces that `asyncio.get_event_loop` will
actually start to call the implementation of the new policy.
agoscinski pushed a commit that referenced this pull request Apr 13, 2026
The `PlumpyEventLoopPolicy` is designed to apply the `nest_asyncio`
patch to the event loop to make it reentrant. Once the policy is applied
using `set_event_loop_policy` the idea is that when calling
`asyncio.get_event_loop` the `get_event_loop` of `PlumpyEventLoopPolicy`
is called instead which will apply the patch to the loop if not already
done before.

However, in a Jupyter notebook, `asyncio.get_event_loop` would not
actually call the patched `get_event_loop` of the policy, even do the
policy was set. This was proved by the fact that calling the method
`asyncio.get_event_loop_policy` would return `PlumpyEventLoopPolicy`. It
was not until `asyncio.get_event_loop_policy().get_event_loop()` was
called that the patch policy was called and the loop was patched.

As a workaround the `set_event_loop_policy` is updated to directly after
setting the new policy to call `get_event_loop_policy`. Through an
unknown mechanism, this forces that `asyncio.get_event_loop` will
actually start to call the implementation of the new policy.
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.

Event loop is not patched in Jupyter notebook even when set_event_loop_policy is called

2 participants