kopia lustrzana https://github.com/simonw/datasette
Avoid current_task warnings in Python 3.8
rodzic
cea151f9cb
commit
877dda2d28
|
@ -9,12 +9,19 @@ tracers = {}
|
||||||
TRACE_RESERVED_KEYS = {"type", "start", "end", "duration_ms", "traceback"}
|
TRACE_RESERVED_KEYS = {"type", "start", "end", "duration_ms", "traceback"}
|
||||||
|
|
||||||
|
|
||||||
|
# asyncio.current_task was introduced in Python 3.7:
|
||||||
|
for obj in (asyncio, asyncio.Task):
|
||||||
|
current_task = getattr(obj, "current_task", None)
|
||||||
|
if current_task is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def get_task_id():
|
def get_task_id():
|
||||||
try:
|
try:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
return None
|
return None
|
||||||
return id(asyncio.Task.current_task(loop=loop))
|
return id(current_task(loop=loop))
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
|
Ładowanie…
Reference in New Issue