-
Notifications
You must be signed in to change notification settings - Fork 20
Support 3.14 #334
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
Merged
Merged
Support 3.14 #334
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,60 +3,32 @@ | |
|
|
||
| import asyncio | ||
| import sys | ||
| from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Sequence | ||
| from typing import TYPE_CHECKING, Any, Callable, Dict, Sequence | ||
|
|
||
| __all__ = [ | ||
| 'PlumpyEventLoopPolicy', | ||
| 'get_event_loop', | ||
| 'new_event_loop', | ||
| 'reset_event_loop_policy', | ||
| 'set_event_loop', | ||
| 'set_event_loop_policy', | ||
| ] | ||
| __all__: list[str] = ['get_or_create_event_loop'] | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .processes import Process | ||
|
|
||
| get_event_loop = asyncio.get_event_loop | ||
|
|
||
|
|
||
| def set_event_loop(*args: Any, **kwargs: Any) -> None: | ||
| raise NotImplementedError('this method is not implemented because `plumpy` uses a single cached event loop') | ||
|
|
||
|
|
||
| def new_event_loop(*args: Any, **kwargs: Any) -> asyncio.AbstractEventLoop: | ||
| raise NotImplementedError('this method is not implemented because `plumpy` uses a single cached event loop') | ||
|
|
||
|
|
||
| class PlumpyEventLoopPolicy(asyncio.DefaultEventLoopPolicy): | ||
| """Custom event policy that always returns the same cached event loop. | ||
|
|
||
| Reentrancy for nested process execution is handled via greenback bridging | ||
| in Process.execute() rather than by patching the event loop. | ||
| def get_or_create_event_loop() -> asyncio.AbstractEventLoop: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file has the most important changes |
||
| """Get the running event loop, or the current set loop, or create and set a new one. | ||
| Note: aiida should never call on asyncio.get_event_loop() directly. | ||
| """ | ||
|
|
||
| _loop: Optional[asyncio.AbstractEventLoop] = None | ||
|
|
||
| def get_event_loop(self) -> asyncio.AbstractEventLoop: | ||
| """Return the cached event loop.""" | ||
| if self._loop is None: | ||
| self._loop = self.new_event_loop() | ||
| self.set_event_loop(self._loop) | ||
|
|
||
| return self._loop | ||
|
|
||
|
|
||
| def set_event_loop_policy() -> None: | ||
| """Enable plumpy's event loop policy that caches a single event loop.""" | ||
| asyncio.set_event_loop_policy(PlumpyEventLoopPolicy()) | ||
| # Need to call the following explicitly for `asyncio.get_event_loop` to start calling the method of the new policy | ||
| # in case an loop is already active. | ||
| asyncio.get_event_loop_policy().get_event_loop() | ||
|
|
||
|
|
||
| def reset_event_loop_policy() -> None: | ||
| """Reset the event loop policy to the default.""" | ||
| asyncio.set_event_loop_policy(None) | ||
| try: | ||
| return asyncio.get_running_loop() | ||
| except RuntimeError: | ||
| pass | ||
| try: | ||
| # See issue https://github.com/aiidateam/plumpy/issues/336 | ||
| loop = asyncio.get_event_loop() | ||
| if not loop.is_closed(): | ||
| return loop | ||
| except RuntimeError: | ||
| pass | ||
| loop = asyncio.new_event_loop() | ||
| asyncio.set_event_loop(loop) | ||
| return loop | ||
|
|
||
|
|
||
| class ProcessCallback: | ||
|
|
||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +0,0 @@ | ||
| # -*- coding: utf-8 -*- | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(scope='session') | ||
| def set_event_loop_policy(): | ||
| from plumpy import set_event_loop_policy | ||
|
|
||
| set_event_loop_policy() | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uv installs python itself