From 9dc617d4a112e9bf31e29ed8d3928139d6fa6d07 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 18 Apr 2025 16:44:23 +0300 Subject: [PATCH 01/34] =?UTF-8?q?=F0=9F=86=95=20feat(loop):=20add=20option?= =?UTF-8?q?al=20overlap=20support=20to=20allow=20concurrent=20loop=20execu?= =?UTF-8?q?tions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a new overlap parameter to the loop decorator and Loop class to control whether loop iterations can run concurrently. When set to True, the next iteration will not wait for the previous one to finish, allowing overlapping executions—useful for long-running tasks that should not delay subsequent runs. Defaults to False to preserve current behavior. Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index af34cc6844..3dc3e24d35 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -91,10 +91,12 @@ def __init__( count: int | None, reconnect: bool, loop: asyncio.AbstractEventLoop, + overlap: bool ) -> None: self.coro: LF = coro self.reconnect: bool = reconnect self.loop: asyncio.AbstractEventLoop = loop + self.overlap: bool = overlap self.count: int | None = count self._current_loop = 0 self._handle: SleepHandle = MISSING @@ -166,7 +168,10 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._last_iteration = self._next_iteration self._next_iteration = self._get_next_sleep_time() try: - await self.coro(*args, **kwargs) + if self.overlap: + asyncio.create_task(self.coro(*args, **kwargs)) + else: + await self.coro(*args, **kwargs) self._last_iteration_failed = False backoff = ExponentialBackoff() except self._valid_exception: @@ -738,6 +743,7 @@ def loop( count: int | None = None, reconnect: bool = True, loop: asyncio.AbstractEventLoop = MISSING, + overlap: bool = False, ) -> Callable[[LF], Loop[LF]]: """A decorator that schedules a task in the background for you with optional reconnect logic. The decorator returns a :class:`Loop`. @@ -774,6 +780,9 @@ def loop( The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`. + overlap: :class:`bool` + Whether to allow the next iteration of the loop to run even if the previous one has not completed. + Raises ------ ValueError @@ -793,6 +802,7 @@ def decorator(func: LF) -> Loop[LF]: time=time, reconnect=reconnect, loop=loop, + overlap=overlap ) return decorator From bfda3aaf62ac9a33ec1816f204fb0cfe6a919582 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:46:22 +0000 Subject: [PATCH 02/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 3dc3e24d35..cc002323ca 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -91,7 +91,7 @@ def __init__( count: int | None, reconnect: bool, loop: asyncio.AbstractEventLoop, - overlap: bool + overlap: bool, ) -> None: self.coro: LF = coro self.reconnect: bool = reconnect @@ -802,7 +802,7 @@ def decorator(func: LF) -> Loop[LF]: time=time, reconnect=reconnect, loop=loop, - overlap=overlap + overlap=overlap, ) return decorator From 8dc95c4db83eab9a136eea9bd5e4bbc829cd0db6 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 18 Apr 2025 16:51:00 +0300 Subject: [PATCH 03/34] Update CHANGELOG.md Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38725e4141..c5b961f0a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2714](https://github.com/Pycord-Development/pycord/pull/2714)) - Added the ability to pass a `datetime.time` object to `format_dt` ([#2747](https://github.com/Pycord-Development/pycord/pull/2747)) +- Added the ability to pass an `overlap` parameter to the `loop` decorator and `Loop` class, allowing concurrent iterations if enabled ([#2765](https://github.com/Pycord-Development/pycord/pull/2765)) ### Fixed From 7dbf3a07c0c3bf27dcd47be0ee281107c9cfc2bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:51:24 +0000 Subject: [PATCH 04/34] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5b961f0a4..a3ea3e4e33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#2714](https://github.com/Pycord-Development/pycord/pull/2714)) - Added the ability to pass a `datetime.time` object to `format_dt` ([#2747](https://github.com/Pycord-Development/pycord/pull/2747)) -- Added the ability to pass an `overlap` parameter to the `loop` decorator and `Loop` class, allowing concurrent iterations if enabled ([#2765](https://github.com/Pycord-Development/pycord/pull/2765)) +- Added the ability to pass an `overlap` parameter to the `loop` decorator and `Loop` + class, allowing concurrent iterations if enabled + ([#2765](https://github.com/Pycord-Development/pycord/pull/2765)) ### Fixed From 1f1ef8ab41497dfe42f04f4729fb7ceb14d7b865 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 18 Apr 2025 16:51:47 +0300 Subject: [PATCH 05/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index cc002323ca..c014cb60e5 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -783,6 +783,8 @@ def loop( overlap: :class:`bool` Whether to allow the next iteration of the loop to run even if the previous one has not completed. + .. versionadded:: 2.7 + Raises ------ ValueError From 570ae99cec957753ca7e6bc2197970c04fd45310 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:07:03 +0300 Subject: [PATCH 06/34] fix- TypeError: Loop.__init__() missing 1 required positional argument: 'overlap' Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index c014cb60e5..13504bf414 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -223,6 +223,7 @@ def __get__(self, obj: T, objtype: type[T]) -> Loop[LF]: count=self.count, reconnect=self.reconnect, loop=self.loop, + overlap=self.overlap, ) copy._injected = obj copy._before_loop = self._before_loop From c8f3bb4990c900d0e5ac6f9cdc255bbdde2212df Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:26:48 +0300 Subject: [PATCH 07/34] fix cancellation using overlap=true Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 13504bf414..37b44bf186 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -117,6 +117,7 @@ def __init__( self._is_being_cancelled = False self._has_failed = False self._stop_next_iteration = False + self._tasks: list[asyncio.Task[Any]] = [] if self.count is not None and self.count <= 0: raise ValueError("count must be greater than 0 or None.") @@ -169,7 +170,8 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._next_iteration = self._get_next_sleep_time() try: if self.overlap: - asyncio.create_task(self.coro(*args, **kwargs)) + task = asyncio.create_task(self.coro(*args, **kwargs)) + self._tasks.append(task) else: await self.coro(*args, **kwargs) self._last_iteration_failed = False @@ -197,6 +199,9 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: except asyncio.CancelledError: self._is_being_cancelled = True + for task in self._tasks: + task.cancel() + await asyncio.gather(*self._tasks, return_exceptions=True) raise except Exception as exc: self._has_failed = True From 463a249b89baaa241e2f0ca352c39f003b8d7077 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 18 Apr 2025 18:20:48 +0300 Subject: [PATCH 08/34] fix Exception in callback Future.set_result(True) handle: Traceback (most recent call last): File "/usr/local/lib/python3.11/asyncio/events.py", line 84, in _run self._context.run(self._callback, *self._args) asyncio.exceptions.InvalidStateError: invalid state Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 37b44bf186..4f820cd5b7 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -59,10 +59,14 @@ def __init__( relative_delta = discord.utils.compute_timedelta(dt) self.handle = loop.call_later(relative_delta, future.set_result, True) + def _set_result_safe(self): + if not self.future.done(): + self.future.set_result(True) + def recalculate(self, dt: datetime.datetime) -> None: self.handle.cancel() relative_delta = discord.utils.compute_timedelta(dt) - self.handle = self.loop.call_later(relative_delta, self.future.set_result, True) + self.handle = loop.call_later(relative_delta, self._set_result_safe) def wait(self) -> asyncio.Future[Any]: return self.future From 26a8ff1ad3344975176607ef2c6bc3b131633792 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 18 Apr 2025 18:25:07 +0300 Subject: [PATCH 09/34] fix identation Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 4f820cd5b7..72035394cd 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -60,8 +60,8 @@ def __init__( self.handle = loop.call_later(relative_delta, future.set_result, True) def _set_result_safe(self): - if not self.future.done(): - self.future.set_result(True) + if not self.future.done(): + self.future.set_result(True) def recalculate(self, dt: datetime.datetime) -> None: self.handle.cancel() From 7e4fd6a684ee8d5e5b0fde821181bffb4a0d87c0 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 11:17:41 +0300 Subject: [PATCH 10/34] Update CHANGELOG.md Co-authored-by: plun1331 Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 202a240913..34c56dbe35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ These changes are available on the `master` branch, but have not yet been releas - Added the ability to pass a `datetime.time` object to `format_dt` ([#2747](https://github.com/Pycord-Development/pycord/pull/2747)) - Added the ability to pass an `overlap` parameter to the `loop` decorator and `Loop` - class, allowing concurrent iterations if enabled + class, allowing concurrent iterations if enabled. ([#2765](https://github.com/Pycord-Development/pycord/pull/2765)) ### Fixed From 1562e642f811fdcfa1d7183c11c1d54658df9656 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 11:19:56 +0300 Subject: [PATCH 11/34] Update discord/ext/tasks/__init__.py Co-authored-by: plun1331 Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 72035394cd..f69d159feb 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -66,7 +66,7 @@ def _set_result_safe(self): def recalculate(self, dt: datetime.datetime) -> None: self.handle.cancel() relative_delta = discord.utils.compute_timedelta(dt) - self.handle = loop.call_later(relative_delta, self._set_result_safe) + self.handle = self.loop.call_later(relative_delta, self._set_result_safe) def wait(self) -> asyncio.Future[Any]: return self.future From 734ce8a1ff8cc3e88f90e68d61489362b419ec2b Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 11:32:07 +0300 Subject: [PATCH 12/34] Update __init__.py add name for the tasks Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index f69d159feb..d0c43b47ac 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERgt LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -174,8 +174,12 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._next_iteration = self._get_next_sleep_time() try: if self.overlap: - task = asyncio.create_task(self.coro(*args, **kwargs)) - self._tasks.append(task) + self._tasks.append( + asyncio.create_task( + self.coro(*args, **kwargs), + name=f"pycord-loop-{self.coro.__name__}" + ) + ) else: await self.coro(*args, **kwargs) self._last_iteration_failed = False From fc137ddd5350eff04f6e18eed6d6d084535ef565 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 08:32:33 +0000 Subject: [PATCH 13/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index d0c43b47ac..baba847dd1 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -177,7 +177,7 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._tasks.append( asyncio.create_task( self.coro(*args, **kwargs), - name=f"pycord-loop-{self.coro.__name__}" + name=f"pycord-loop-{self.coro.__name__}", ) ) else: From 0898f82320d3740122893a0dee804881f29229c5 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 11:33:33 +0300 Subject: [PATCH 14/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index baba847dd1..6fb690bce9 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -177,7 +177,7 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._tasks.append( asyncio.create_task( self.coro(*args, **kwargs), - name=f"pycord-loop-{self.coro.__name__}", + name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", ) ) else: From 209232f20d34fbcdde7f520a209cb3480efc9415 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 11:55:21 +0300 Subject: [PATCH 15/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 6fb690bce9..f4a27fcdf8 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -95,12 +95,12 @@ def __init__( count: int | None, reconnect: bool, loop: asyncio.AbstractEventLoop, - overlap: bool, + overlap: bool | int, ) -> None: self.coro: LF = coro self.reconnect: bool = reconnect self.loop: asyncio.AbstractEventLoop = loop - self.overlap: bool = overlap + self.overlap: bool | int = overlap self.count: int | None = count self._current_loop = 0 self._handle: SleepHandle = MISSING @@ -135,6 +135,15 @@ def __init__( raise TypeError( f"Expected coroutine function, not {type(self.coro).__name__!r}." ) + if isinstance(overlap, bool): + self._semaphore = asyncio.Semaphore(1 if not overlap else math.inf) + elif isinstance(overlap, int): + if overlap <= 0: + raise ValueError("overlap as an integer must be greater than 0.") + self._semaphore = asyncio.Semaphore(overlap) + else: + raise TypeError("overlap must be a bool or a positive integer.") + async def _call_loop_function(self, name: str, *args: Any, **kwargs: Any) -> None: coro = getattr(self, f"_{name}") @@ -173,15 +182,14 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._last_iteration = self._next_iteration self._next_iteration = self._get_next_sleep_time() try: - if self.overlap: - self._tasks.append( - asyncio.create_task( - self.coro(*args, **kwargs), - name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", - ) - ) - else: - await self.coro(*args, **kwargs) + async def run_with_semaphore(): + async with self._semaphore: + await self.coro(*args, **kwargs) + + self._tasks.append(asyncio.create_task( + run_with_semaphore(), + name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", + )) self._last_iteration_failed = False backoff = ExponentialBackoff() except self._valid_exception: @@ -757,7 +765,7 @@ def loop( count: int | None = None, reconnect: bool = True, loop: asyncio.AbstractEventLoop = MISSING, - overlap: bool = False, + overlap: bool | int = False, ) -> Callable[[LF], Loop[LF]]: """A decorator that schedules a task in the background for you with optional reconnect logic. The decorator returns a :class:`Loop`. @@ -794,8 +802,12 @@ def loop( The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`. - overlap: :class:`bool` - Whether to allow the next iteration of the loop to run even if the previous one has not completed. + overlap: Union[:class:`bool`, :class:`int`] + Controls whether to allow overlapping executions of the loop task. + + - If set to :class:`False` (default), the next iteration waits until the previous finishes. + - If set to :class:`True`, overlapping executions are allowed with no limit. + - If set to an :class:`int`, allows up to that many overlapping executions at once. .. versionadded:: 2.7 From f24682a9b1238194923c26333c5c5b182db80d57 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 11:55:45 +0300 Subject: [PATCH 16/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index f4a27fcdf8..f423133612 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERgt +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -25,6 +25,7 @@ from __future__ import annotations +import math import asyncio import datetime import inspect From 49bf2b7bb5650f371f670c97c5956662ccd2a9b7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 08:55:47 +0000 Subject: [PATCH 17/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index f423133612..65a4abbe59 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -145,7 +145,6 @@ def __init__( else: raise TypeError("overlap must be a bool or a positive integer.") - async def _call_loop_function(self, name: str, *args: Any, **kwargs: Any) -> None: coro = getattr(self, f"_{name}") if coro is None: @@ -183,14 +182,17 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._last_iteration = self._next_iteration self._next_iteration = self._get_next_sleep_time() try: + async def run_with_semaphore(): async with self._semaphore: await self.coro(*args, **kwargs) - - self._tasks.append(asyncio.create_task( - run_with_semaphore(), - name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", - )) + + self._tasks.append( + asyncio.create_task( + run_with_semaphore(), + name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", + ) + ) self._last_iteration_failed = False backoff = ExponentialBackoff() except self._valid_exception: @@ -805,7 +807,7 @@ def loop( overlap: Union[:class:`bool`, :class:`int`] Controls whether to allow overlapping executions of the loop task. - + - If set to :class:`False` (default), the next iteration waits until the previous finishes. - If set to :class:`True`, overlapping executions are allowed with no limit. - If set to an :class:`int`, allows up to that many overlapping executions at once. From 071731eb042fc811b41551ec34d49701149d8982 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 18:26:19 +0300 Subject: [PATCH 18/34] implemented a way of adding a limit of concurrency Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 65a4abbe59..5a96f0f986 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -136,14 +136,13 @@ def __init__( raise TypeError( f"Expected coroutine function, not {type(self.coro).__name__!r}." ) - if isinstance(overlap, bool): - self._semaphore = asyncio.Semaphore(1 if not overlap else math.inf) + if not isinstance(overlap, (bool, int)): + raise TypeError("overlap must be a bool or a positive integer.") elif isinstance(overlap, int): - if overlap <= 0: - raise ValueError("overlap as an integer must be greater than 0.") + if overlap <= 1: + raise ValueError("overlap as an integer must be greater than 1.") self._semaphore = asyncio.Semaphore(overlap) - else: - raise TypeError("overlap must be a bool or a positive integer.") + async def _call_loop_function(self, name: str, *args: Any, **kwargs: Any) -> None: coro = getattr(self, f"_{name}") @@ -182,17 +181,19 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._last_iteration = self._next_iteration self._next_iteration = self._get_next_sleep_time() try: - - async def run_with_semaphore(): - async with self._semaphore: - await self.coro(*args, **kwargs) - - self._tasks.append( - asyncio.create_task( - run_with_semaphore(), - name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", + if not self.overlap: + await self.coro(*args, **kwargs) + else: + async def run_with_semaphore(): + async with self._semaphore: + await self.coro(*args, **kwargs) + + self._tasks.append( + asyncio.create_task( + self.coro(*args, **kwargs) if self.overlap is True else run_with_semaphore(), + name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", + ) ) - ) self._last_iteration_failed = False backoff = ExponentialBackoff() except self._valid_exception: From e2ef4a675351587c1c9479614cd11548f1b3da45 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 15:26:47 +0000 Subject: [PATCH 19/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 5a96f0f986..8401985c21 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -25,7 +25,6 @@ from __future__ import annotations -import math import asyncio import datetime import inspect @@ -142,7 +141,6 @@ def __init__( if overlap <= 1: raise ValueError("overlap as an integer must be greater than 1.") self._semaphore = asyncio.Semaphore(overlap) - async def _call_loop_function(self, name: str, *args: Any, **kwargs: Any) -> None: coro = getattr(self, f"_{name}") @@ -184,13 +182,18 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: if not self.overlap: await self.coro(*args, **kwargs) else: + async def run_with_semaphore(): async with self._semaphore: await self.coro(*args, **kwargs) - + self._tasks.append( asyncio.create_task( - self.coro(*args, **kwargs) if self.overlap is True else run_with_semaphore(), + ( + self.coro(*args, **kwargs) + if self.overlap is True + else run_with_semaphore() + ), name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", ) ) From 1623f10e674dd02a863e097bce2f3938f2b3e6cb Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 18:37:12 +0300 Subject: [PATCH 20/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 8401985c21..d5fff576a1 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -25,6 +25,7 @@ from __future__ import annotations +import math import asyncio import datetime import inspect @@ -137,10 +138,11 @@ def __init__( ) if not isinstance(overlap, (bool, int)): raise TypeError("overlap must be a bool or a positive integer.") - elif isinstance(overlap, int): + elif overlap is not False and isinstance(overlap, int): if overlap <= 1: raise ValueError("overlap as an integer must be greater than 1.") self._semaphore = asyncio.Semaphore(overlap) + async def _call_loop_function(self, name: str, *args: Any, **kwargs: Any) -> None: coro = getattr(self, f"_{name}") @@ -182,18 +184,13 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: if not self.overlap: await self.coro(*args, **kwargs) else: - async def run_with_semaphore(): async with self._semaphore: await self.coro(*args, **kwargs) - + self._tasks.append( asyncio.create_task( - ( - self.coro(*args, **kwargs) - if self.overlap is True - else run_with_semaphore() - ), + self.coro(*args, **kwargs) if self.overlap is True else run_with_semaphore(), name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", ) ) From 47c8796f66ab5eb75d3871443f9ce03123f9346c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 15:37:35 +0000 Subject: [PATCH 21/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index d5fff576a1..c579c95e87 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -25,7 +25,6 @@ from __future__ import annotations -import math import asyncio import datetime import inspect @@ -142,7 +141,6 @@ def __init__( if overlap <= 1: raise ValueError("overlap as an integer must be greater than 1.") self._semaphore = asyncio.Semaphore(overlap) - async def _call_loop_function(self, name: str, *args: Any, **kwargs: Any) -> None: coro = getattr(self, f"_{name}") @@ -184,13 +182,18 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: if not self.overlap: await self.coro(*args, **kwargs) else: + async def run_with_semaphore(): async with self._semaphore: await self.coro(*args, **kwargs) - + self._tasks.append( asyncio.create_task( - self.coro(*args, **kwargs) if self.overlap is True else run_with_semaphore(), + ( + self.coro(*args, **kwargs) + if self.overlap is True + else run_with_semaphore() + ), name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", ) ) From c689c818277c00ce30514cdc2d3fb52db648063c Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 18:39:47 +0300 Subject: [PATCH 22/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index c579c95e87..3c2274b98f 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -137,7 +137,7 @@ def __init__( ) if not isinstance(overlap, (bool, int)): raise TypeError("overlap must be a bool or a positive integer.") - elif overlap is not False and isinstance(overlap, int): + elif isinstance(overlap, bool) and isinstance(overlap, int): if overlap <= 1: raise ValueError("overlap as an integer must be greater than 1.") self._semaphore = asyncio.Semaphore(overlap) From ef0f28e9c8ca3897eb9c480cfb9709435ecbcc91 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 18:42:19 +0300 Subject: [PATCH 23/34] missing not Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 3c2274b98f..878358c8b1 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -137,7 +137,7 @@ def __init__( ) if not isinstance(overlap, (bool, int)): raise TypeError("overlap must be a bool or a positive integer.") - elif isinstance(overlap, bool) and isinstance(overlap, int): + elif not isinstance(overlap, bool) and isinstance(overlap, int): if overlap <= 1: raise ValueError("overlap as an integer must be greater than 1.") self._semaphore = asyncio.Semaphore(overlap) From 0cfb1113bd2f57241ffd5b18648f61c52eb099ce Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 19:13:03 +0300 Subject: [PATCH 24/34] test contextvars Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 878358c8b1..4ba528fec5 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -30,6 +30,7 @@ import inspect import sys import traceback +import contextvars from collections.abc import Sequence from typing import Any, Awaitable, Callable, Generic, TypeVar, cast @@ -39,6 +40,8 @@ from discord.backoff import ExponentialBackoff from discord.utils import MISSING + + __all__ = ("loop",) T = TypeVar("T") @@ -46,7 +49,7 @@ LF = TypeVar("LF", bound=_func) FT = TypeVar("FT", bound=_func) ET = TypeVar("ET", bound=Callable[[Any, BaseException], Awaitable[Any]]) - +_current_loop_ctx: contextvars.ContextVar[int] = contextvars.ContextVar("_current_loop_ctx", default=0) class SleepHandle: __slots__ = ("future", "loop", "handle") @@ -179,6 +182,7 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None: self._last_iteration = self._next_iteration self._next_iteration = self._get_next_sleep_time() try: + token = _current_loop_ctx.set(self._current_loop) if not self.overlap: await self.coro(*args, **kwargs) else: @@ -197,6 +201,7 @@ async def run_with_semaphore(): name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", ) ) + _current_loop_ctx.reset(token) self._last_iteration_failed = False backoff = ExponentialBackoff() except self._valid_exception: @@ -303,7 +308,7 @@ def time(self) -> list[datetime.time] | None: @property def current_loop(self) -> int: """The current iteration of the loop.""" - return self._current_loop + return _current_loop_ctx.get() @property def next_iteration(self) -> datetime.datetime | None: From b3b1a454f9e2fdbeffcf104e40eaf90d5efa3044 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 16:13:51 +0000 Subject: [PATCH 25/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 4ba528fec5..1174ff3b50 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -26,11 +26,11 @@ from __future__ import annotations import asyncio +import contextvars import datetime import inspect import sys import traceback -import contextvars from collections.abc import Sequence from typing import Any, Awaitable, Callable, Generic, TypeVar, cast @@ -40,8 +40,6 @@ from discord.backoff import ExponentialBackoff from discord.utils import MISSING - - __all__ = ("loop",) T = TypeVar("T") From 3c255e6d86bf9dd15b7d5277c87afaf0cceae05c Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 19:22:31 +0300 Subject: [PATCH 26/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 1174ff3b50..755b5b96e9 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -26,11 +26,11 @@ from __future__ import annotations import asyncio -import contextvars import datetime import inspect import sys import traceback +import contextvars from collections.abc import Sequence from typing import Any, Awaitable, Callable, Generic, TypeVar, cast @@ -40,6 +40,8 @@ from discord.backoff import ExponentialBackoff from discord.utils import MISSING + + __all__ = ("loop",) T = TypeVar("T") @@ -306,7 +308,7 @@ def time(self) -> list[datetime.time] | None: @property def current_loop(self) -> int: """The current iteration of the loop.""" - return _current_loop_ctx.get() + return _current_loop_ctx.get() or self.current_loop @property def next_iteration(self) -> datetime.datetime | None: From 82da2d86fb20fd29daf9d80fad67826d2e0f687c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 16:24:06 +0000 Subject: [PATCH 27/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 755b5b96e9..762fd8296d 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -26,11 +26,11 @@ from __future__ import annotations import asyncio +import contextvars import datetime import inspect import sys import traceback -import contextvars from collections.abc import Sequence from typing import Any, Awaitable, Callable, Generic, TypeVar, cast @@ -40,8 +40,6 @@ from discord.backoff import ExponentialBackoff from discord.utils import MISSING - - __all__ = ("loop",) T = TypeVar("T") From c7bb8852352b2fe5986052a38dc3ffd2d5d545a3 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 19:25:17 +0300 Subject: [PATCH 28/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 762fd8296d..f53c5d8a1e 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -47,7 +47,10 @@ LF = TypeVar("LF", bound=_func) FT = TypeVar("FT", bound=_func) ET = TypeVar("ET", bound=Callable[[Any, BaseException], Awaitable[Any]]) -_current_loop_ctx: contextvars.ContextVar[int] = contextvars.ContextVar("_current_loop_ctx", default=0) +_current_loop_ctx: contextvars.ContextVar[int] = contextvars.ContextVar( + "_current_loop_ctx", default=0 +) + class SleepHandle: __slots__ = ("future", "loop", "handle") @@ -306,7 +309,7 @@ def time(self) -> list[datetime.time] | None: @property def current_loop(self) -> int: """The current iteration of the loop.""" - return _current_loop_ctx.get() or self.current_loop + return _current_loop_ctx.get() or self.current_loop @property def next_iteration(self) -> datetime.datetime | None: From 64e9fb4f0cd2d6a4e491664c5bda44e7ade4c001 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 19:26:51 +0300 Subject: [PATCH 29/34] wrong indents Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index f53c5d8a1e..200518be11 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -309,7 +309,7 @@ def time(self) -> list[datetime.time] | None: @property def current_loop(self) -> int: """The current iteration of the loop.""" - return _current_loop_ctx.get() or self.current_loop + return _current_loop_ctx.get() or self._current_loop @property def next_iteration(self) -> datetime.datetime | None: From 51cb3b9141f72791a5de2023e58321feac7546c8 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 19:39:28 +0300 Subject: [PATCH 30/34] removed tasks when done Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 200518be11..37ee5cba35 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -192,16 +192,17 @@ async def run_with_semaphore(): async with self._semaphore: await self.coro(*args, **kwargs) - self._tasks.append( - asyncio.create_task( - ( - self.coro(*args, **kwargs) - if self.overlap is True - else run_with_semaphore() - ), - name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", - ) + task = asyncio.create_task( + ( + self.coro(*args, **kwargs) + if self.overlap is True + else run_with_semaphore() + ), + name=f"pycord-loop-{self.coro.__name__}-{self._current_loop}", ) + task.add_done_callback(self._tasks.remove) + self._tasks.append(task) + _current_loop_ctx.reset(token) self._last_iteration_failed = False backoff = ExponentialBackoff() From ea7c2a27fbdf1169e986d6004f8b47732f7a5038 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Thu, 1 May 2025 19:42:47 +0300 Subject: [PATCH 31/34] fix first iteration current loop not working Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 37ee5cba35..bca6b3c429 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -48,7 +48,7 @@ FT = TypeVar("FT", bound=_func) ET = TypeVar("ET", bound=Callable[[Any, BaseException], Awaitable[Any]]) _current_loop_ctx: contextvars.ContextVar[int] = contextvars.ContextVar( - "_current_loop_ctx", default=0 + "_current_loop_ctx", default=None ) @@ -310,7 +310,11 @@ def time(self) -> list[datetime.time] | None: @property def current_loop(self) -> int: """The current iteration of the loop.""" - return _current_loop_ctx.get() or self._current_loop + return ( + _current_loop_ctx.get() + if _current_loop_ctx.get() is not None + else self._current_loop + ) @property def next_iteration(self) -> datetime.datetime | None: From fec336a69579513b66e6cc7fc3e5e6341a47c151 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 23 May 2025 09:06:51 +0300 Subject: [PATCH 32/34] Update __init__.py Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index bca6b3c429..ea82afde74 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -821,7 +821,7 @@ def loop( defaults to :func:`asyncio.get_event_loop`. overlap: Union[:class:`bool`, :class:`int`] - Controls whether to allow overlapping executions of the loop task. + Controls whether to allow overlapping executions of the task loop. - If set to :class:`False` (default), the next iteration waits until the previous finishes. - If set to :class:`True`, overlapping executions are allowed with no limit. From 18dc1800b6615cd0dbea6780cd991ec7d3c87f22 Mon Sep 17 00:00:00 2001 From: Lumouille <144063653+Lumabots@users.noreply.github.com> Date: Fri, 23 May 2025 09:12:15 +0300 Subject: [PATCH 33/34] Update __init__.py Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com> --- discord/ext/tasks/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index ea82afde74..3900512333 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -819,14 +819,10 @@ def loop( loop: :class:`asyncio.AbstractEventLoop` The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`. - overlap: Union[:class:`bool`, :class:`int`] - Controls whether to allow overlapping executions of the task loop. - - - If set to :class:`False` (default), the next iteration waits until the previous finishes. - - If set to :class:`True`, overlapping executions are allowed with no limit. - - If set to an :class:`int`, allows up to that many overlapping executions at once. - + Controls whether overlapping executions of the task loop are allowed. + Set to False (default) to run iterations one at a time, True for unlimited overlap, or an int to cap the number of concurrent runs. + .. versionadded:: 2.7 Raises From 4ecf027af9f7cb67b92905160d97a7dd5d924c21 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 06:12:43 +0000 Subject: [PATCH 34/34] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/tasks/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 3900512333..5276427e7d 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -822,7 +822,7 @@ def loop( overlap: Union[:class:`bool`, :class:`int`] Controls whether overlapping executions of the task loop are allowed. Set to False (default) to run iterations one at a time, True for unlimited overlap, or an int to cap the number of concurrent runs. - + .. versionadded:: 2.7 Raises