-
Notifications
You must be signed in to change notification settings - Fork 137
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
make BlockingPortal.stop sync #334
base: master
Are you sure you want to change the base?
make BlockingPortal.stop sync #334
Conversation
d77d139
to
e0ff495
Compare
e0ff495
to
2adff23
Compare
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.
If this method is made synchronous, we need to ensure that people dont try to use it from external threads. At the very least, a warning against that should be added to the docstring. The event.set()
call should raise a clear enough error but I feel that the event loop thread id member set should be moved to after the event set, to be safe.
src/anyio/from_thread.py
Outdated
self._stop_event.set() | ||
self._event_loop_thread_id = None |
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.
This should avoid breakage when called from external threads.
self._stop_event.set() | |
self._event_loop_thread_id = None | |
if self._event_loop_thread_id is None: | |
return | |
if threading.get_ident() != self._event_loop_thread_id: | |
raise RuntimeError('This method must be called from the event loop thread') | |
self._event_loop_thread_id = None | |
self._stop_event.set() |
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
@@ -154,11 +155,18 @@ async def stop(self, cancel_remaining: bool = False) -> None: | |||
finish before returning | |||
|
|||
""" | |||
if self._event_loop_thread_id is None: |
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.
ah this is wrong - we need to handle cancel_remaining
No description provided.