Skip to content

Commit d88e48b

Browse files
committed
fast_io Improve code comments around pend_throw.
1 parent c3f859a commit d88e48b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fast_io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def wait(self, delay):
103103
if isinstance(cb, tuple):
104104
cb[0](*cb[1])
105105
else:
106-
cb.pend_throw(None) # Clears the pend_throw(False) executed when IOWrite was yielded
106+
cb.pend_throw(None) # Ensure that, if task is cancelled, it doesn't get queued again
107107
self._call_io(cb) # Put coro onto runq (or ioq if one exists)
108108
if ev & select.POLLIN:
109109
cb = self.rdobjmap[id(sock)]

fast_io/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def run_forever(self):
200200
if isinstance(ret, After):
201201
delay = int(delay*1000)
202202
elif isinstance(ret, IORead): # coro was a StreamReader read method
203-
cb.pend_throw(False) # Why? I think this is for debugging. If it is scheduled other than by wait
203+
cb.pend_throw(False) # If task is cancelled or times out, it is put on runq to process exception.
204+
# Note if it is scheduled other than by wait
204205
# (which does pend_throw(None) an exception (exception doesn't inherit from Exception) is thrown
205206
self.add_reader(arg, cb) # Set up select.poll for read and store the coro in object map
206207
continue # Don't reschedule. Coro is scheduled by wait() when poll indicates h/w ready
@@ -361,7 +362,7 @@ def __next__(self):
361362

362363
def cancel(coro):
363364
prev = coro.pend_throw(CancelledError())
364-
if prev is False:
365+
if prev is False: # Not on runq so put it there
365366
_event_loop.call_soon(coro)
366367

367368

0 commit comments

Comments
 (0)