Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpylog committed Jul 31, 2022
1 parent e2a5d3f commit 1b03b29
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
11 changes: 9 additions & 2 deletions django_q/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions django_q/core_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions django_q/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
)
)
Expand Down
16 changes: 10 additions & 6 deletions django_q/timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b03b29

Please sign in to comment.