Skip to content

Commit

Permalink
fix: tasks loop infinitely when tzinfo is neither None nor UTC (#…
Browse files Browse the repository at this point in the history
…2196)

* Resolve task unlimited repeat bug

Signed-off-by: Jeon Hojin <[email protected]>

* Fix bug for first init

Signed-off-by: Jeon Hojin <[email protected]>

* fix bug for 2nd or above

Signed-off-by: Jeon Hojin <[email protected]>

* add fix to CHANGELOG.md

Signed-off-by: Jeon Hojin <[email protected]>

* change : Naive한 경우 누락된 거 수정

Signed-off-by: Jeon Hojin <[email protected]>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update CHANGELOG.md

Co-authored-by: JustaSqu1d <[email protected]>
Signed-off-by: Jeon Hojin <[email protected]>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update discord/ext/tasks/__init__.py

Co-authored-by: Dorukyum <[email protected]>
Signed-off-by: Jeon Hojin <[email protected]>

* Update discord/ext/tasks/__init__.py

Co-authored-by: Dorukyum <[email protected]>
Signed-off-by: Jeon Hojin <[email protected]>

* Update discord/ext/tasks/__init__.py

Co-authored-by: Dorukyum <[email protected]>
Signed-off-by: Jeon Hojin <[email protected]>

* Update discord/ext/tasks/__init__.py

Co-authored-by: Dorukyum <[email protected]>
Signed-off-by: Jeon Hojin <[email protected]>

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update CHANGELOG.md

Signed-off-by: Dorukyum <[email protected]>

* oops

Signed-off-by: Dorukyum <[email protected]>

---------

Signed-off-by: Jeon Hojin <[email protected]>
Signed-off-by: Dorukyum <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: JustaSqu1d <[email protected]>
Co-authored-by: Lala Sabathil <[email protected]>
Co-authored-by: Dorukyum <[email protected]>
  • Loading branch information
5 people authored Nov 26, 2023
1 parent f6ac778 commit 2437c7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ These changes are available on the `master` branch, but have not yet been releas
`None`. ([#2219](https://github.com/Pycord-Development/pycord/pull/2219))
- Fixed ffmpeg being terminated prematurely when piping audio stream.
([#2240](https://github.com/Pycord-Development/pycord/pull/2240))
- Fixed tasks looping infinitely when `tzinfo` is neither `None` nor UTC.
([#2196](https://github.com/Pycord-Development/pycord/pull/2196))

## [2.4.1] - 2023-03-20

Expand Down
18 changes: 13 additions & 5 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _get_next_sleep_time(self) -> datetime.datetime:
if self._current_loop == 0:
# if we're at the last index on the first iteration, we need to sleep until tomorrow
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(self._time[0].tzinfo or datetime.timezone.utc)
+ datetime.timedelta(days=1),
self._time[0],
)
Expand All @@ -584,18 +584,26 @@ def _get_next_sleep_time(self) -> datetime.datetime:

if self._current_loop == 0:
self._time_index += 1
if next_time > datetime.datetime.now(datetime.timezone.utc).timetz():
if (
next_time
> datetime.datetime.now(
next_time.tzinfo or datetime.timezone.utc
).timetz()
):
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc), next_time
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc),
next_time,
)
else:
return datetime.datetime.combine(
datetime.datetime.now(datetime.timezone.utc)
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc)
+ datetime.timedelta(days=1),
next_time,
)

next_date = cast(datetime.datetime, self._last_iteration)
next_date = cast(
datetime.datetime, self._last_iteration.astimezone(next_time.tzinfo)
)
if next_time < next_date.timetz():
next_date += datetime.timedelta(days=1)

Expand Down

0 comments on commit 2437c7e

Please sign in to comment.