Trigger application of nest patch in set_event_loop_policy#189
Merged
Trigger application of nest patch in set_event_loop_policy#189
set_event_loop_policy#189Conversation
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.
678c073 to
32cfafc
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #188
The
PlumpyEventLoopPolicyis designed to apply thenest_asynciopatch to the event loop to make it reentrant. Once the policy is applied
using
set_event_loop_policythe idea is that when callingasyncio.get_event_looptheget_event_loopofPlumpyEventLoopPolicyis called instead which will apply the patch to the loop if not already
done before.
However, in a Jupyter notebook,
asyncio.get_event_loopwould notactually call the patched
get_event_loopof the policy, even do thepolicy was set. This was proved by the fact that calling the method
asyncio.get_event_loop_policywould returnPlumpyEventLoopPolicy. Itwas not until
asyncio.get_event_loop_policy().get_event_loop()wascalled that the patch policy was called and the loop was patched.
As a workaround the
set_event_loop_policyis updated to directly aftersetting the new policy to call
get_event_loop_policy. Through anunknown mechanism, this forces that
asyncio.get_event_loopwillactually start to call the implementation of the new policy.