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

Revert removing of SyncToAsync.get_current_task #454

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ def thread_handler(self, loop, exc_info, task_context, func, *args, **kwargs):
else:
return func(*args, **kwargs)

@staticmethod
def get_current_task() -> Optional["asyncio.Task[Any]"]:
"""
Implementation of asyncio.current_task()
that returns None if there is no task.
"""
try:
return asyncio.current_task()
except RuntimeError:
return None

@overload
def async_to_sync(
Expand Down
Loading