Skip to content

Commit

Permalink
Fixes the asyncio.all_tasks PY37 in a different way
Browse files Browse the repository at this point in the history
  • Loading branch information
HazardDede committed May 1, 2020
1 parent 1b42852 commit 1172a3c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pnp/engines/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ def _stop(self) -> None:
async def _wait_for_tasks_to_complete(self) -> None:
"""Check if something is still running on the event loop (like running pushes) so that the
event loop will not terminate but wait for pending tasks."""

if hasattr(asyncio, "all_tasks"):
# PY >= 3.7
pending_tasks_fun = asyncio.all_tasks
else:
pending_tasks_fun = asyncio.Task.all_tasks

async def _pending_tasks_exist() -> bool:
all_tasks = list(asyncio.Task.all_tasks())
all_tasks = list(pending_tasks_fun())
for task in all_tasks:
if task.done():
continue
current = str(task)
# Is a push running?
if "coro=<AsyncEngine._schedule_push()" in str(current):
Expand Down

0 comments on commit 1172a3c

Please sign in to comment.