Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "coroutine was never awaited" warnings #929

Draft
wants to merge 3 commits into
base: branch-0.31
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ucp/continuous_ucx_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def __init__(self, worker, event_loop):
self.event_loop = event_loop
self.asyncio_task = None

def __del__(self):
if self.asyncio_task is not None:
self.asyncio_task.cancel()

# Hash and equality is based on the event loop
def __hash__(self):
return hash(self.event_loop)
Expand Down Expand Up @@ -83,6 +79,11 @@ def _fd_reader_callback(self):
# Notice, we can safely overwrite `self.dangling_arm_task`
# since previous arm task is finished by now.
assert self.asyncio_task is None or self.asyncio_task.done()
from .core import has_context_referrers

if not has_context_referrers():
self.asyncio_task = None
return
self.asyncio_task = self.event_loop.create_task(self._arm_worker())

async def _arm_worker(self):
Expand Down
12 changes: 10 additions & 2 deletions ucp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ApplicationContext:
"""

def __init__(self, config_dict={}, blocking_progress_mode=None):
self.progress_tasks = []
self.progress_tasks = dict()

# For now, a application context only has one worker
self.context = ucx_api.UCXContext(config_dict)
Expand Down Expand Up @@ -407,7 +407,7 @@ def continuous_ucx_progress(self, event_loop=None):
task = BlockingMode(self.worker, loop, self.epoll_fd)
else:
task = NonBlockingMode(self.worker, loop)
self.progress_tasks.append(task)
self.progress_tasks[loop] = task

def get_ucp_worker(self):
"""Returns the underlying UCP worker handle (ucp_worker_h)
Expand Down Expand Up @@ -926,6 +926,14 @@ def init(options={}, env_takes_precedence=False, blocking_progress_mode=None):
_ctx = ApplicationContext(options, blocking_progress_mode=blocking_progress_mode)


def has_context_referrers():
global _ctx
if _ctx is not None:
weakref_ctx = weakref.ref(_ctx)
# gc.collect()
return weakref_ctx() is None


def reset():
"""Resets the UCX library by shutting down all of UCX.

Expand Down