Repository navigation
Conversation
run_until_complete making the next run stop earlyrun_until_complete making the next run stop early
|
Thank you for the review, @deadlovelll! |
kumaraditya303
left a comment
There was a problem hiding this comment.
There is a much simpler fix for this:
@@ -188,7 +188,11 @@ def _run_until_complete_cb(fut):
# Issue #22429: run_forever() already finished, no need to
# stop it.
return
- futures._get_loop(fut).stop()
+ loop = futures._get_loop(fut)
+ # gh-158406: the callback can outlive the run_until_complete() call
+ # that registered it; it must not stop a later run of the loop.
+ if loop._run_until_complete_fut is fut:
+ loop.stop()
@@ -431,6 +435,7 @@ def __init__(self):
self._timer_cancelled_count = 0
self._closed = False
self._stopping = False
+ self._run_until_complete_fut = None
self._ready = collections.deque()
self._scheduled = []
self._default_executor = None
@@ -713,6 +718,7 @@ def run_until_complete(self, future):
future._log_destroy_pending = False
future.add_done_callback(_run_until_complete_cb)
+ self._run_until_complete_fut = future
try:
self.run_forever()
except:
@@ -723,6 +729,7 @@ def run_until_complete(self, future):
future.exception()
raise
finally:
+ self._run_until_complete_fut = None
future.remove_done_callback(_run_until_complete_cb)
if not future.done():
raise RuntimeError('Event loop stopped before Future completed.')
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Thanks for the review. I switched to this approach with an adjustment in 090a6e7. Instead of One thing to note is that this approach means that code that registers |
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @kumaraditya303: please review the changes made to this pull request. |
run_until_complete()now records the future it is waiting on in a private attribute on the loop, and clears it when the call returns._run_until_complete_cbonly stops the loop while that attribute is set and its future is done. Thus, a callback that is still queued when the call returns no longer stops a laterrun_until_complete()orrun_forever().The registered callback is still
_run_until_complete_cb, so AnyIO, which finds its root task by looking for that callback, behaves as it does onmain.Closes gh-158406.