Commit 5173f5e1 authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files


parent 6a2a886f
......@@ -105,6 +105,19 @@ def report_error(fmt, *k):
traceback.format_exception_only(type(e), e)[-1].strip())
def disable_future_warning(fut):
"""Add a dummy callback to a future to prevent asyncio warnings
Return: the future
The asynicio module log a warning message when the result of a future is
not used. This function installs a dummy callback to the future so as to
avoid this warning. This is useful for futures whose result *may* be
ignored by the application.
fut.add_done_callback(lambda f: f.exception())
return fut
def auto_create_task(func):
"""Decorator for forcing the creation of a task when a coroutine function is called
......@@ -115,12 +128,8 @@ def auto_create_task(func):
assert asyncio.iscoroutinefunction(func)
def wrapper(*k, **kw):
tsk = asyncio.async(func(*k, **kw))
# ignore warning about result not used
tsk.add_done_callback(lambda f: f.exception())
return tsk
return wrapper
return (lambda *k, **kw:
disable_future_warning(asyncio.async(func(*k, **kw))))
def cascade_future(src, dst):
"""propagate the result of a future to another future
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment