Skip to content

Commit

Permalink
Fix routine entering recursive loop with .restart
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Dec 29, 2024
1 parent 1556f41 commit ff02ae1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions twitchio/ext/routines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ async def _call_error(self, error: Exception) -> None:
await self._on_error(error)

async def _routine_loop(self, *args: Any, **kwargs: Any) -> None:
self._args = args
self._kwargs = kwargs

backoff: Backoff = Backoff(base=3, maximum_time=10, maximum_tries=5)

if self._should_stop:
Expand Down Expand Up @@ -266,6 +263,22 @@ async def _routine_loop(self, *args: Any, **kwargs: Any) -> None:

self.cancel()

@property
def args(self) -> tuple[Any, ...]:
"""|prop|
Property returning any positional arguments passed to the routine via :meth:`.start`.
"""
return self._args

@property
def kwargs(self) -> Any:
"""|prop|
Property returning any keyword arguments passed to the routine via :meth:`.start`.
"""
return self._kwargs

def start(self, *args: Any, **kwargs: Any) -> asyncio.Task[None]:
r"""Method to start the :class:`~Routine` in the background.
Expand All @@ -288,6 +301,9 @@ def start(self, *args: Any, **kwargs: Any) -> asyncio.Task[None]:
if self._task and not self._task.done() and not self._restarting:
raise RuntimeError(f"Routine {self!r} is currently running and has not completed.")

self._args = args
self._kwargs = kwargs

if self._injected:
args = (self._injected, *args)

Expand Down

0 comments on commit ff02ae1

Please sign in to comment.