Skip to content
Snippets Groups Projects
Commit 2fe37e7c authored by inso's avatar inso
Browse files

Fix bug with exception never handled in once_at_a_time coroutines

parent 6568b487
No related branches found
No related tags found
No related merge requests found
...@@ -13,15 +13,24 @@ def cancel_once_task(object, fn): ...@@ -13,15 +13,24 @@ def cancel_once_task(object, fn):
def once_at_a_time(fn): def once_at_a_time(fn):
@functools.wraps(fn) @functools.wraps(fn)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
def task_done(task):
try:
args[0].__tasks.pop(fn.__name__)
except KeyError:
logging.debug("Task already removed")
if getattr(args[0], "__tasks", None) is None: if getattr(args[0], "__tasks", None) is None:
setattr(args[0], "__tasks", {}) setattr(args[0], "__tasks", {})
if fn.__name__ in args[0].__tasks: if fn.__name__ in args[0].__tasks:
if not args[0].__tasks[fn.__name__].done(): if not args[0].__tasks[fn.__name__].done():
args[0].__tasks[fn.__name__].cancel() args[0].__tasks[fn.__name__].cancel()
try: try:
args[0].__tasks[fn.__name__] = fn(*args, **kwargs) args[0].__tasks[fn.__name__] = fn(*args, **kwargs)
args[0].__tasks[fn.__name__].add_done_callback(task_done)
except asyncio.CancelledError: except asyncio.CancelledError:
logging.debug("Cancelled asyncified : {0}".format(fn.__name__)) logging.debug("Cancelled asyncified : {0}".format(fn.__name__))
return args[0].__tasks[fn.__name__] return args[0].__tasks[fn.__name__]
return wrapper return wrapper
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment