mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-04 10:48:12 +08:00
Checks if cpu_count is implemented
On rare occasions, usually on win32, cpu_count will raise a NotImplemented error. If psutil is installed we will use this to get the correct count, otherwise we default to 4
This commit is contained in:
+1
-7
@@ -22,12 +22,6 @@ from multiprocessing import Queue, Event, Process, Value, current_process
|
|||||||
# external
|
# external
|
||||||
import arrow
|
import arrow
|
||||||
|
|
||||||
# optional
|
|
||||||
try:
|
|
||||||
import psutil
|
|
||||||
except ImportError:
|
|
||||||
psutil = None
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@@ -37,7 +31,7 @@ from django import db
|
|||||||
import signing
|
import signing
|
||||||
import tasks
|
import tasks
|
||||||
|
|
||||||
from django_q.conf import Conf, redis_client, logger
|
from django_q.conf import Conf, redis_client, logger, psutil
|
||||||
from django_q.models import Task, Success, Schedule
|
from django_q.models import Task, Success, Schedule
|
||||||
from django_q.monitor import Status, Stat
|
from django_q.monitor import Status, Stat
|
||||||
|
|
||||||
|
|||||||
+22
-2
@@ -2,10 +2,19 @@ import logging
|
|||||||
from signal import signal
|
from signal import signal
|
||||||
from multiprocessing import cpu_count, Queue
|
from multiprocessing import cpu_count, Queue
|
||||||
|
|
||||||
|
# django
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
# external
|
||||||
import redis
|
import redis
|
||||||
|
|
||||||
|
# optional
|
||||||
|
try:
|
||||||
|
import psutil
|
||||||
|
except ImportError:
|
||||||
|
psutil = None
|
||||||
|
|
||||||
|
|
||||||
class Conf(object):
|
class Conf(object):
|
||||||
"""
|
"""
|
||||||
@@ -36,8 +45,19 @@ class Conf(object):
|
|||||||
# Maximum number of tasks that each cluster can work on
|
# Maximum number of tasks that each cluster can work on
|
||||||
QUEUE_LIMIT = conf.get('queue_limit', None)
|
QUEUE_LIMIT = conf.get('queue_limit', None)
|
||||||
|
|
||||||
# Number of workers in the pool. Default is cpu count. +2 for monitor and pusher
|
# Number of workers in the pool. Default is cpu count if implemented, otherwise 4.
|
||||||
WORKERS = conf.get('workers', cpu_count())
|
WORKERS = conf.get('workers', False)
|
||||||
|
if not WORKERS:
|
||||||
|
try:
|
||||||
|
WORKERS = cpu_count()
|
||||||
|
# in rare cases this might fail
|
||||||
|
except NotImplementedError:
|
||||||
|
# try psutil
|
||||||
|
if psutil:
|
||||||
|
WORKERS = psutil.cpu_count() or 4
|
||||||
|
else:
|
||||||
|
# sensible default
|
||||||
|
WORKERS = 4
|
||||||
|
|
||||||
# Sets compression of redis packages
|
# Sets compression of redis packages
|
||||||
COMPRESSED = conf.get('compress', False)
|
COMPRESSED = conf.get('compress', False)
|
||||||
|
|||||||
Reference in New Issue
Block a user