Update tracing library to be python 3.9 compatible.
`asyncio.Task.current_task()` was deprecated in python 3.7 and removed in 3.9.
This was replaced by `asyncio.current_task()`.
@@ -286,9 +286,15 @@ _non_async_span_yields = ThreadLocalSpanYields()
def _current_task() -> Optional[asyncio.Task]:
+ """Get the current running task, or `None` if no task is running."""
+ # Note: `current_task` returns `None` if there is no current task, but it
+ # throws if no currently running async loop.
try:
- # Note: `current_task` returns `None` if there is no current task,
- # but it throws if no currently running async loop.
+ # asyncio.Task.current_task was moved to asyncio.current_task() starting
+ # with 3.9, but previoulsy was asyncio.Task.current() until Python 3.6.
+ if sys.version_info[1] >= 7:
+ return asyncio.current_task()
+ else:
return asyncio.Task.current_task()
except RuntimeError:
return None
