Skip to content

Commit

Permalink
add current_task support for tasks.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Aug 17, 2023
1 parent 3b28e0e commit fb1561d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "socketify"
version = "0.0.25"
version = "0.0.26"
dynamic = ["dependencies"]
authors = [
{ name="Ciro Spaciari", email="[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

setuptools.setup(
name="socketify",
version="0.0.25",
version="0.0.26",
platforms=["any"],
author="Ciro Spaciari",
author_email="[email protected]",
Expand Down
15 changes: 12 additions & 3 deletions src/socketify/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
exceptions,
futures,
_register_task,
# _enter_task,
# current_task,
# _leave_task,
_enter_task,
current_task,
_leave_task,
_unregister_task,
)
import contextvars
Expand Down Expand Up @@ -92,6 +92,7 @@ class RequestTask:
# status is still pending
_log_destroy_pending = True

_parent_task = None
def __init__(
self, coro, loop, default_done_callback=None, no_register=False, context=None
):
Expand Down Expand Up @@ -498,6 +499,11 @@ def __step(self, exc=None):
self._must_cancel = False
coro = self._coro
self._fut_waiter = None

# _parent_task = current_task(self._loop)
# if _parent_task is not None:
# _leave_task(self._loop, _parent_task)
# self._parent_task = _parent_task
# _enter_task(self._loop, self)
# Call either coro.throw(exc) or coro.send(None).
try:
Expand Down Expand Up @@ -569,6 +575,9 @@ def __step(self, exc=None):
self._loop.call_soon(self.__step, new_exc, context=self._context)
finally:
# _leave_task(self._loop, self)
# if self._parent_task is not None:
# _enter_task(self._loop, self._parent_task)
# self._parent_task = None
self = None # Needed to break cycles when an exception occurs.

def __wakeup(self, future):
Expand Down

0 comments on commit fb1561d

Please sign in to comment.