提交 5bf84305 编辑于 作者: Zachary Garrett's avatar Zachary Garrett 提交者: tensorflow-copybara
浏览文件

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()`.
https://docs.python.org/3.8/library/asyncio-task.html#asyncio.Task.current_task

PiperOrigin-RevId: 374223589
上级 7db06855
......@@ -286,10 +286,16 @@ _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.
return asyncio.Task.current_task()
# 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
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册