mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-03 09:28:12 +08:00
#56 fakes setting cpu_affinity on unsupported platforms
This commit is contained in:
+6
-1
@@ -431,7 +431,7 @@ def scheduler(broker=None):
|
|||||||
# get args, kwargs and hook
|
# get args, kwargs and hook
|
||||||
if s.kwargs:
|
if s.kwargs:
|
||||||
try:
|
try:
|
||||||
# eval should be safe here cause dict()
|
# eval should be safe here because dict()
|
||||||
kwargs = eval('dict({})'.format(s.kwargs))
|
kwargs = eval('dict({})'.format(s.kwargs))
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
@@ -499,7 +499,12 @@ def set_cpu_affinity(n, process_ids, actual=not Conf.TESTING):
|
|||||||
"""
|
"""
|
||||||
# check if we have the psutil module
|
# check if we have the psutil module
|
||||||
if not psutil:
|
if not psutil:
|
||||||
|
logger.warning('Skipping cpu affinity because psutil was not found.')
|
||||||
return
|
return
|
||||||
|
# check if the platform supports cpu_affinity
|
||||||
|
if actual and not hasattr(psutil.Process(process_ids[0]), 'cpu_affinity'):
|
||||||
|
logger.warning('Faking cpu affinity because it is not supported on this platform')
|
||||||
|
actual = False
|
||||||
# get the available processors
|
# get the available processors
|
||||||
cpu_list = list(range(psutil.cpu_count()))
|
cpu_list = list(range(psutil.cpu_count()))
|
||||||
# affinities of 0 or gte cpu_count, equals to no affinity
|
# affinities of 0 or gte cpu_count, equals to no affinity
|
||||||
|
|||||||
@@ -117,6 +117,5 @@ CACHES = {
|
|||||||
# Django Q specific
|
# Django Q specific
|
||||||
Q_CLUSTER = {'name': 'django_q_test',
|
Q_CLUSTER = {'name': 'django_q_test',
|
||||||
'cpu_affinity': 1,
|
'cpu_affinity': 1,
|
||||||
'testing': True,
|
|
||||||
'log_level': 'DEBUG',
|
'log_level': 'DEBUG',
|
||||||
'django_redis': 'default'}
|
'django_redis': 'default'}
|
||||||
|
|||||||
@@ -269,6 +269,8 @@ As a rule of thumb; cpu_affinity 1 favors repetitive short running tasks, while
|
|||||||
|
|
||||||
The ``cpu_affinity`` setting requires the optional :ref:`psutil <psutil>` module.
|
The ``cpu_affinity`` setting requires the optional :ref:`psutil <psutil>` module.
|
||||||
|
|
||||||
|
*Psutil does not support cpu affinity on OS X at this time.*
|
||||||
|
|
||||||
.. py:module:: django_q
|
.. py:module:: django_q
|
||||||
|
|
||||||
.. rubric:: Footnotes
|
.. rubric:: Footnotes
|
||||||
|
|||||||
+1
-1
@@ -137,7 +137,7 @@ In this example the user requests a report and we let the cluster do the generat
|
|||||||
task.result)
|
task.result)
|
||||||
|
|
||||||
|
|
||||||
The hook is practical here, cause it allows us to detach the sending task from the report generation function and to report on possible failures.
|
The hook is practical here, because it allows us to detach the sending task from the report generation function and to report on possible failures.
|
||||||
|
|
||||||
Haystack
|
Haystack
|
||||||
========
|
========
|
||||||
|
|||||||
Reference in New Issue
Block a user