diff --git a/django_q/cluster.py b/django_q/cluster.py index 1682ccaa..0609e113 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -212,7 +212,11 @@ def spawn_pusher(self) -> Process: def spawn_worker(self): self.spawn_process( - worker, self.task_queue, self.result_queue, Value('I', WorkerStatus.IDLE.value), self.timeout + worker, + self.task_queue, + self.result_queue, + Value("I", WorkerStatus.IDLE.value), + self.timeout, ) def spawn_monitor(self) -> Process: @@ -277,7 +281,10 @@ def guard(self): for p in self.pool: with p.status.get_lock(): # Are you alive? - if not p.is_alive() or p.status.value in {WorkerStatus.TIMEOUT.value, WorkerStatus.RECYCLE.value}: + if not p.is_alive() or p.status.value in { + WorkerStatus.TIMEOUT.value, + WorkerStatus.RECYCLE.value, + }: self.reincarnate(p) continue # Check Monitor diff --git a/django_q/core_signing.py b/django_q/core_signing.py index c7d0086a..80f23fae 100644 --- a/django_q/core_signing.py +++ b/django_q/core_signing.py @@ -6,10 +6,12 @@ from django.core.signing import Signer as Sgnr from django.core.signing import TimestampSigner as TsS from django.core.signing import b64_decode, dumps + try: from django.core.signing import b62_decode except ImportError: from django.utils.baseconv import base62 + b62_decode = base62.decode from django.utils.crypto import constant_time_compare from django.utils.encoding import force_bytes, force_str diff --git a/django_q/monitor.py b/django_q/monitor.py index 97404187..cb881418 100644 --- a/django_q/monitor.py +++ b/django_q/monitor.py @@ -26,7 +26,7 @@ def get_process_mb(pid): try: process = psutil.Process(pid) - mb_used = round(process.memory_info().rss / 1024 ** 2, 2) + mb_used = round(process.memory_info().rss / 1024**2, 2) except psutil.NoSuchProcess: mb_used = "NO_PROCESS_FOUND" return mb_used @@ -372,7 +372,7 @@ def memory(run_once=False, workers=False, broker=None): ) # memory available (MB) memory_available = round( - psutil.virtual_memory().available / 1024 ** 2, 2 + psutil.virtual_memory().available / 1024**2, 2 ) if memory_available_percentage < MEMORY_AVAILABLE_LOWEST_PERCENTAGE: MEMORY_AVAILABLE_LOWEST_PERCENTAGE = memory_available_percentage @@ -396,7 +396,7 @@ def memory(run_once=False, workers=False, broker=None): print( term.move(row, 4 * col_width) + term.center( - round(psutil.virtual_memory().total / 1024 ** 2, 2), + round(psutil.virtual_memory().total / 1024**2, 2), width=col_width - 1, ) ) diff --git a/django_q/timeouts.py b/django_q/timeouts.py index 64a6925a..287ae8d0 100644 --- a/django_q/timeouts.py +++ b/django_q/timeouts.py @@ -6,17 +6,21 @@ from typing import Optional -class JobTimeoutException(Exception): - """Raised when a job takes longer to complete than the allowed maximum +class JobTimeoutException(BaseException): + """ + Raised when a job takes longer to complete than the allowed maximum timeout value. """ + pass class BaseDeathPenalty: """Base class to setup job timeouts.""" - def __init__(self, timeout:Optional[float], exception=JobTimeoutException, **kwargs): + def __init__( + self, timeout: Optional[float], exception=JobTimeoutException, **kwargs + ): if timeout is None: # If signal.alarm timeout is 0, no alarm will be scheduled # by signal.alarm @@ -51,10 +55,10 @@ def cancel_death_penalty(self): class UnixSignalDeathPenalty(BaseDeathPenalty): - def handle_death_penalty(self, signum, frame): - raise self._exception('Task exceeded maximum timeout value ' - '({0} seconds)'.format(self._timeout)) + raise self._exception( + "Task exceeded maximum timeout value " "({0} seconds)".format(self._timeout) + ) def setup_death_penalty(self): """Sets up an alarm signal and a signal handler that raises