asyncio: Handle case where waio_io_event returns early

pull/9870/head
Jared Hancock 2024-03-09 10:44:08 -06:00
rodzic 0e5e1ffaa5
commit c4b3fb43a0
1 zmienionych plików z 15 dodań i 13 usunięć

Wyświetl plik

@ -153,21 +153,23 @@ def run_until_complete(main_task=None):
global cur_task global cur_task
excs_all = (CancelledError, Exception) # To prevent heap allocation in loop excs_all = (CancelledError, Exception) # To prevent heap allocation in loop
excs_stop = (CancelledError, StopIteration) # To prevent heap allocation in loop excs_stop = (CancelledError, StopIteration) # To prevent heap allocation in loop
_io_queue.wait_io_event(0)
while True: while True:
try: try:
# Wait until the head of _task_queue is ready to run while True:
t = _task_queue.peek() # Wait until the head of _task_queue is ready to run
if t: t = _task_queue.peek()
# A task waiting on _task_queue; "ph_key" is time to schedule task at if t:
dt = ticks_diff(t.ph_key, ticks()) # A task waiting on _task_queue; "ph_key" is time to schedule task at
_io_queue.wait_io_event(dt if dt > 0 else 0) dt = ticks_diff(t.ph_key, ticks())
elif not _io_queue.map: _io_queue.wait_io_event(dt if dt > 0 else 0)
# No tasks can be woken so finished running if dt <= 0:
cur_task = None break
return elif not _io_queue.map:
else: # No tasks can be woken so finished running
_io_queue.wait_io_event(-1) cur_task = None
return
else:
_io_queue.wait_io_event(-1)
except BaseException as exc: except BaseException as exc:
try: try:
if main_task: if main_task: