Repository: Bogdanp/django_dramatiq

Issue:
`rundramatiq` thread count defaults to `CPU_COUNT`
If an explicit thread count is not supplied to `rundramatiq`, it defaults to `CPU_COUNT`. This is inconsistent with the `dramatiq` cli, which is `8`. This seems like a sensible default, as the threads param is threads _per process_. Should the `rundramatiq` default be updated to `8` as well?

Discussion:

Patch:
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
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 @@ from django.utils.module_loading import module_has_submodule
 
 #: The number of available CPUs.
 CPU_COUNT = multiprocessing.cpu_count()
+THREAD_COUNT = 8
 
 
 class Command(BaseCommand):
@@ -52,9 +53,9 @@ class Command(BaseCommand):
         )
         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",


Test patch:
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",