From 218f8f66c3723228b1341ee4349a5be649b81368 Mon Sep 17 00:00:00 2001 From: Andrew Graham-Yooll Date: Fri, 27 Dec 2024 11:45:14 +0100 Subject: [PATCH 1/2] Set thread count to 8 as per dramatiq default --- .../management/commands/rundramatiq.py | 5 ++-- tests/test_rundramatiq_command.py | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/django_dramatiq/management/commands/rundramatiq.py b/django_dramatiq/management/commands/rundramatiq.py index 438b2a7..6401ddf 100644 --- a/django_dramatiq/management/commands/rundramatiq.py +++ b/django_dramatiq/management/commands/rundramatiq.py @@ -12,6 +12,7 @@ #: The number of available CPUs. CPU_COUNT = multiprocessing.cpu_count() +THREAD_COUNT = 8 class Command(BaseCommand): @@ -52,9 +53,9 @@ def add_arguments(self, parser): ) parser.add_argument( "--threads", "-t", - default=CPU_COUNT, + default=THREAD_COUNT, type=int, - help="The number of threads per process to use (default: %d)." % CPU_COUNT, + help="The number of threads per process to use (default: %d)." % THREAD_COUNT, ) parser.add_argument( "--path", "-P", diff --git a/tests/test_rundramatiq_command.py b/tests/test_rundramatiq_command.py index 2e363ee..9dcee9e 100644 --- a/tests/test_rundramatiq_command.py +++ b/tests/test_rundramatiq_command.py @@ -37,6 +37,7 @@ def test_rundramatiq_can_run_dramatiq(execvp_mock): # And execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -44,7 +45,7 @@ def test_rundramatiq_can_run_dramatiq(execvp_mock): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "django_dramatiq.setup", "django_dramatiq.tasks", @@ -67,6 +68,7 @@ def test_rundramatiq_can_run_dramatiq_reload(execvp_mock): # Then execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -74,7 +76,7 @@ def test_rundramatiq_can_run_dramatiq_reload(execvp_mock): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "--watch", ".", "django_dramatiq.setup", @@ -98,6 +100,7 @@ def test_rundramatiq_can_run_dramatiq_with_polling(execvp_mock): # Then execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -105,7 +108,7 @@ def test_rundramatiq_can_run_dramatiq_with_polling(execvp_mock): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "--watch", ".", "--watch-use-polling", @@ -130,6 +133,7 @@ def test_rundramatiq_can_run_dramatiq_with_only_some_queues(execvp_mock): # Then execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -137,7 +141,7 @@ def test_rundramatiq_can_run_dramatiq_with_only_some_queues(execvp_mock): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "django_dramatiq.setup", "django_dramatiq.tasks", @@ -161,6 +165,7 @@ def test_rundramatiq_can_run_dramatiq_with_specified_pid_file(execvp_mock): # Then execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -168,7 +173,7 @@ def test_rundramatiq_can_run_dramatiq_with_specified_pid_file(execvp_mock): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "django_dramatiq.setup", "django_dramatiq.tasks", @@ -192,6 +197,7 @@ def test_rundramatiq_can_run_dramatiq_with_specified_log_file(execvp_mock): # Then execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -199,7 +205,7 @@ def test_rundramatiq_can_run_dramatiq_with_specified_log_file(execvp_mock): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "django_dramatiq.setup", "django_dramatiq.tasks", @@ -239,6 +245,7 @@ def test_rundramatiq_can_ignore_modules(execvp_mock, settings): # And execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -246,7 +253,7 @@ def test_rundramatiq_can_ignore_modules(execvp_mock, settings): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "django_dramatiq.setup", "django_dramatiq.tasks", @@ -266,6 +273,7 @@ def test_rundramatiq_can_fork(execvp_mock, settings): # Then execvp should be called with the appropriate arguments cores = str(rundramatiq.CPU_COUNT) + threads = str(rundramatiq.THREAD_COUNT) expected_exec_name = "dramatiq" expected_exec_path = os.path.join( os.path.dirname(sys.executable), @@ -273,7 +281,7 @@ def test_rundramatiq_can_fork(execvp_mock, settings): ) execvp_mock.assert_called_once_with(expected_exec_path, [ - expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores, + expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads, "--worker-shutdown-timeout", "600000", "--fork-function", "a", "--fork-function", "b", From 17e4314ed51f2d018d8bb8de5d647b2c1ba5597a Mon Sep 17 00:00:00 2001 From: Andrew Graham-Yooll Date: Fri, 27 Dec 2024 11:53:14 +0100 Subject: [PATCH 2/2] Update the changelog --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d3c397..c5629bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased +### Changed +- Set thread count to 8 as per dramatiq default. Fix [#153]. ([@andrewgy8], [#170]) + +[@andrewgy8]: https://github.com/andrewgy8 +[#153]: https://github.com/Bogdanp/django_dramatiq/issues/153 +[#170]: https://github.com/Bogdanp/django_dramatiq/pull/170 + +### Added +- Display task details in the admin when JSONEncoder is not used. Fix [#135]. ([@huubbouma], [#136]) +- Support for Python 3.13 +- Support for Django 5.1 + +[@huubbouma]: https://github.com/huubbouma +[#135]: https://github.com/Bogdanp/django_dramatiq/issues/135 +[#136]: https://github.com/Bogdanp/django_dramatiq/pull/136 + +### Dropped +- Support for Python 3.8 +- Support for Django 3.2 ## [0.11.6] - 2023-12-12 ### Added