Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 21fe14c

Browse files
author
Drew Freiberger
committed
Address deprecation of asyncio.Task.all_tasks() - issue openstack-charmers#445
1 parent 3eae083 commit 21fe14c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

zaza/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import asyncio
1717
import logging
1818
from pkgutil import extend_path
19+
from sys import version_info
1920

2021

2122
__path__ = extend_path(__path__, __name__)
@@ -40,8 +41,16 @@ def run(*steps):
4041

4142
# Let's also cancel any remaining tasks:
4243
while True:
43-
pending_tasks = [p for p in asyncio.Task.all_tasks()
44-
if not p.done()]
44+
# issue #445 - asyncio.Task.all_tasks() deprecated in 3.7
45+
if version_info.major == 3 and version_info.minor >= 7:
46+
try:
47+
tasklist = asyncio.all_tasks()
48+
except RuntimeError:
49+
# no running event loop
50+
break
51+
else:
52+
tasklist = asyncio.Task.all_tasks()
53+
pending_tasks = [p for p in tasklist if not p.done()]
4554
if pending_tasks:
4655
logging.info(
4756
"async -> sync. cleaning up pending tasks: len: {}"

0 commit comments

Comments
 (0)