Skip to content

Commit

Permalink
Fix #656 -- Add Python 3.13 support (#659)
Browse files Browse the repository at this point in the history
* Fix #656 -- Add Python 3.13 support

`threading.Thread` received a new `_handle` attribute in Python 3.13, which clashes with dramatiq's `_CtypesTimeoutManager(Thread)` class. This commit renames the dramatiq method to resolve the conflict.

It also adds Python 3.13 to CI and package classification

* Fix mypy typing issue in actor.py
  • Loading branch information
amureki authored Oct 26, 2024
1 parent 3e20bdd commit 15c7466
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-python@v4
with:
python-version: "3.12"
python-version: "3.13"
- run: |
sudo apt-get update
sudo apt-get remove libhashkit2 libmemcached11 || true
Expand All @@ -23,7 +23,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-20.04"]
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
concurrency: ["cpython", "gevent"]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
python-version: "3.13"

- name: Install dependencies
run: python -m pip install build
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def send_with_options(
message = self.message_with_options(args=args, kwargs=kwargs, **options)
return self.broker.enqueue(message, delay=delay)

def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Any | R | Awaitable[R]:
"""Synchronously call this actor.
Parameters:
Expand Down
4 changes: 2 additions & 2 deletions dramatiq/middleware/time_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(self, interval, logger=None):
self.logger = logger or get_logger(__name__, type(self))
self.mu = threading.RLock()

def _handle(self):
def _handle_deadlines(self):
current_time = monotonic()
threads_to_kill = []
with self.mu:
Expand All @@ -110,7 +110,7 @@ def _handle(self):
def run(self):
while True:
try:
self._handle()
self._handle_deadlines()
except Exception: # pragma: no cover
self.logger.exception("Unhandled error while running the time limit handler.")

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def rel(*xs):
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
"Topic :: System :: Distributed Computing",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
Expand Down
2 changes: 1 addition & 1 deletion tests/middleware/test_time_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_time_limit_exceeded_worker_messages(raise_thread_exception, caplog):
1: current_time - 2, 2: current_time - 1, 3: current_time + 50000}

# When the time limit handler is triggered
middleware.manager._handle()
middleware.manager._handle_deadlines()

# TimeLimitExceeded interrupts are raised in two of the threads
raise_thread_exception.assert_has_calls([
Expand Down

0 comments on commit 15c7466

Please sign in to comment.