mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-06 18:38:11 +08:00
Adds psutil support for max_rss on other platforms
This commit is contained in:
+18
-7
@@ -20,14 +20,21 @@ from django.utils.translation import gettext_lazy as _
|
||||
# Local
|
||||
import django_q.tasks
|
||||
from django_q.brokers import get_broker, Broker
|
||||
from django_q.conf import Conf, logger, psutil, get_ppid, error_reporter
|
||||
from django_q.conf import (
|
||||
Conf,
|
||||
logger,
|
||||
psutil,
|
||||
get_ppid,
|
||||
error_reporter,
|
||||
croniter,
|
||||
resource,
|
||||
)
|
||||
from django_q.humanhash import humanize
|
||||
from django_q.models import Task, Success, Schedule
|
||||
from django_q.queues import Queue
|
||||
from django_q.signals import pre_execute
|
||||
from django_q.signing import SignedPackage, BadSignature
|
||||
from django_q.status import Stat, Status
|
||||
from django_q import croniter, resource
|
||||
|
||||
|
||||
class Cluster:
|
||||
@@ -434,11 +441,7 @@ def worker(
|
||||
result_queue.put(task)
|
||||
timer.value = -1 # Idle
|
||||
# Recycle
|
||||
if task_count == Conf.RECYCLE or (
|
||||
resource
|
||||
and Conf.MAX_RSS
|
||||
and resource.getrusage(resource.RUSAGE_SELF).ru_maxrss >= Conf.MAX_RSS
|
||||
):
|
||||
if task_count == Conf.RECYCLE or rss_check():
|
||||
timer.value = -2 # Recycled
|
||||
break
|
||||
logger.info(_(f"{name} stopped doing work"))
|
||||
@@ -697,3 +700,11 @@ def set_cpu_affinity(n: int, process_ids: list, actual: bool = not Conf.TESTING)
|
||||
if actual:
|
||||
p.cpu_affinity(affinity)
|
||||
logger.info(_(f"{pid} will use cpu {affinity}"))
|
||||
|
||||
|
||||
def rss_check():
|
||||
if Conf.MAX_RSS and resource:
|
||||
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss >= Conf.MAX_RSS
|
||||
elif Conf.MAX_RSS and psutil:
|
||||
return psutil.Process().memory_info().rss >= Conf.MAX_RSS * 1024
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user