Skip to content

Commit

Permalink
try using Task.cancel(msg) to distinguish internal/external cancel
Browse files Browse the repository at this point in the history
(python 3.9+ only)

related kyuupichan#44

(this does not fix the race condition fully, only ~1 out of 2 orderings)
  • Loading branch information
SomberNight committed Feb 15, 2022
1 parent e55950f commit f6b9437
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions aiorpcx/curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,11 @@ class UncaughtTimeoutError(Exception):
pass


_INTERNAL_TIMEOUT_CANCEL = object()
def _set_new_deadline(task, deadline):
def timeout_task():
# Unfortunately task.cancel is all we can do with asyncio
task.cancel()
task.cancel(_INTERNAL_TIMEOUT_CANCEL)
task._timed_out = deadline
task._deadline_handle = task._loop.call_at(deadline, timeout_task)

Expand Down Expand Up @@ -375,7 +376,7 @@ async def __aexit__(self, exc_type, exc_value, traceback):
if exc_type not in (CancelledError, TaskTimeout,
TimeoutCancellationError):
return False
if timed_out_deadline == self._deadline:
if exc_type is CancelledError and _INTERNAL_TIMEOUT_CANCEL in exc_value.args:
self.expired = True
if self._ignore:
return True
Expand Down

0 comments on commit f6b9437

Please sign in to comment.