Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor run_parallel method to use threading instead of ThreadPoolEx…
…ecutor for task execution
  • Loading branch information
rroblf01 committed Nov 18, 2025
commit 0eb3b190c4901f36e834ec3f08eeae60a7ebc49f
14 changes: 9 additions & 5 deletions django_tasks/backends/database/management/commands/db_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import time
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction
from concurrent.futures import ThreadPoolExecutor
from threading import Thread
from types import FrameType

from django.conf import settings
Expand Down Expand Up @@ -89,10 +89,14 @@ def reset_signals(self) -> None:
signal.signal(signal.SIGQUIT, signal.SIG_DFL)

def run_parallel(self) -> None:
with ThreadPoolExecutor(max_workers=self.max_threads) as executor:
futures = [executor.submit(self.run) for _ in range(self.max_threads)]
for future in futures:
future.result()
threads = []
for _ in range(self.max_threads):
t = Thread(target=self.run, daemon=True)
threads.append(t)
t.start()

for t in threads:
t.join()

def run(self) -> None:
logger.info(
Expand Down