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).
pull/234/merge
Paul Sokolovsky 2017-12-14 19:05:23 +02:00
rodzic 0137449f1f
commit 203cc489c6
1 zmienionych plików z 6 dodań i 1 usunięć

Wyświetl plik

@ -104,9 +104,11 @@ class EventLoop:
if isinstance(ret, SleepMs):
delay = arg
elif isinstance(ret, IORead):
cb.pend_throw(False)
self.add_reader(arg, cb)
continue
elif isinstance(ret, IOWrite):
cb.pend_throw(False)
self.add_writer(arg, cb)
continue
elif isinstance(ret, IOReadDone):
@ -242,7 +244,10 @@ def wait_for_ms(coro, timeout):
if timeout_obj.coro:
if __debug__ and DEBUG:
log.debug("timeout_func: cancelling %s", timeout_obj.coro)
timeout_obj.coro.pend_throw(TimeoutError())
prev = timeout_obj.coro.pend_throw(TimeoutError())
#print("prev pend", prev)
if prev is False:
_event_loop.call_soon(timeout_obj.coro)
timeout_obj = TimeoutObj(_event_loop.cur_task)
_event_loop.call_later_ms(timeout, timeout_func, timeout_obj)