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

Commit

Permalink
Adds the ability to set the process title for things like top or ps
Browse files Browse the repository at this point in the history
  • Loading branch information
stumpylog committed Sep 12, 2022
1 parent 21ef911 commit 8b5289d
Show file tree
Hide file tree
Showing 3 changed files with 381 additions and 312 deletions.
10 changes: 10 additions & 0 deletions django_q/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# External
import arrow

try:
from setproctitle import setproctitle as setprocname
except ImportError:
def setprocname(*args, **kwargs): # noqa
pass

# Django
from django import core, db
from django.apps.registry import apps
Expand Down Expand Up @@ -152,6 +158,7 @@ def __init__(
timeout=Conf.TIMEOUT,
start=True,
):
setprocname("Q Sentinel")
# Make sure we catch signals for the pool
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_DFL)
Expand Down Expand Up @@ -346,6 +353,7 @@ def pusher(task_queue: Queue, event: Event, broker: Broker = None):
:type task_queue: multiprocessing.Queue
:type event: multiprocessing.Event
"""
setprocname("Q Task Pusher")
if not broker:
broker = get_broker()
logger.info(_(f"{current_process().name} pushing tasks at {current_process().pid}"))
Expand Down Expand Up @@ -381,6 +389,7 @@ def monitor(result_queue: Queue, broker: Broker = None):
:type broker: brokers.Broker
:type result_queue: multiprocessing.Queue
"""
setprocname("Q Result Monitor")
if not broker:
broker = get_broker()
name = current_process().name
Expand Down Expand Up @@ -417,6 +426,7 @@ def worker(
:type result_queue: multiprocessing.Queue
:type timer: multiprocessing.Value wrapping an unsigned int
"""
setprocname("Q Worker")
name = current_process().name
logger.info(_(f"{name} ready for work at {current_process().pid}"))
task_count = 0
Expand Down
Loading

0 comments on commit 8b5289d

Please sign in to comment.