-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-42392: Remove loop parameter form asyncio locks and Queue #23420
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
152ac8a
Remove loop parameter form asyncio locks and Queue
uriyyo 66fff45
Update Lib/asyncio/mixins.py
uriyyo 0c764ff
Update Lib/asyncio/mixins.py
uriyyo a37d2bd
Remove __all__ for asyncio.mixins
uriyyo 6b3ecfb
Update _LoopBoundedMixin class usage
uriyyo 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
Next
Next commit
Remove loop parameter form asyncio locks and Queue
- Loading branch information
commit 152ac8a23dc2470910d6fdd461dbfe36e8e44c9f
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Event loop mixins.""" | ||
|
||
__all__ = ('LoopBoundedMixin',) | ||
uriyyo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import threading | ||
from . import events | ||
|
||
global_lock = threading.Lock() | ||
uriyyo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class LoopBoundedMixin: | ||
uriyyo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_loop = None | ||
|
||
def _get_loop(self): | ||
loop = events._get_running_loop() | ||
|
||
if self._loop is None: | ||
with global_lock: | ||
if self._loop is None: | ||
self._loop = loop | ||
if loop is not self._loop: | ||
raise RuntimeError | ||
return loop |
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
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.
I'd actually keep the
loop=None
parameter and add something like this: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.
I thought that we should fully remove
loop
parameter because it deprecated.Maybe it's better to fully remove
loop
as for me it a lit bit confusing to have a parameter that raises an exception when it set, it looks the same as we won't haveloop
parameter when it set we will receive an error that init method doesn't acceptloop
but it has a drawback - exception message won't be such explicit.What is your opinion?
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.
We could do
marker=object()
and then use theloop=marker
default to make it better. But I'm also not 100% about my own suggestion here :) @asvetlov thoughts?Uh oh!
There was an error while loading. Please reload this page.
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.
I'm +1 for raising an explicit error and using the sentinel approach to check if the user passed a loop arg. Especially with how widespread the loop parameter is used throughout existing asyncio code, it's going to be a much smoother transition to have an error message that tells users precisely what they did incorrect rather than the parameter just disappearing.
(Also keeping in mind the unfortunate reality that not everyone tests with deprecation warnings on, or might not have gotten around to removing loop throughout their own code since the warnings started in 3.8)
As for when the parameter should just be removed entirely without an explicit error message, I think doing that in 3.11 or 3.12 would be fine.
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.
Now I get it, sorry that didn't understand it the first time.
Give an explicit error will be better for debugging and will make the transition much easier.
I will update #23499 to use this approach regarding the
loop
parameter.Uh oh!
There was an error while loading. Please reload this page.
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.
Although I would make the message a little bit more direct and technically specific:
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.
loop=marker
looks a little more protective but, I think, the whole idea is a slight overcomplication.For me, "removal" means exactly removal but I can live with the proposed change.