kopia lustrzana https://github.com/micropython/micropython-lib
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
rodzic
0137449f1f
commit
203cc489c6
|
@ -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)
|
||||
|
|
Ładowanie…
Reference in New Issue