Skip to content

Commit 203cc48

Browse files
committed
uasyncio.core: wait_for: Add support for cancelling I/O-bound coros.
Coros which removed from normal scheduling queue (and possibly put into another queue, like I/O queue here) are marked with .pend_throw(False). If wait_for() cancels such a coro, it is explicitly scheduled for execution, so they actually could process pending exception (coro's exception handler should take care of removing it from another queue and related clean up).
1 parent 0137449 commit 203cc48

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

uasyncio.core/uasyncio/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ def run_forever(self):
104104
if isinstance(ret, SleepMs):
105105
delay = arg
106106
elif isinstance(ret, IORead):
107+
cb.pend_throw(False)
107108
self.add_reader(arg, cb)
108109
continue
109110
elif isinstance(ret, IOWrite):
111+
cb.pend_throw(False)
110112
self.add_writer(arg, cb)
111113
continue
112114
elif isinstance(ret, IOReadDone):
@@ -242,7 +244,10 @@ def timeout_func(timeout_obj):
242244
if timeout_obj.coro:
243245
if __debug__ and DEBUG:
244246
log.debug("timeout_func: cancelling %s", timeout_obj.coro)
245-
timeout_obj.coro.pend_throw(TimeoutError())
247+
prev = timeout_obj.coro.pend_throw(TimeoutError())
248+
#print("prev pend", prev)
249+
if prev is False:
250+
_event_loop.call_soon(timeout_obj.coro)
246251

247252
timeout_obj = TimeoutObj(_event_loop.cur_task)
248253
_event_loop.call_later_ms(timeout, timeout_func, timeout_obj)

0 commit comments

Comments
 (0)