diff --git a/django_q/cluster.py b/django_q/cluster.py index f7332fb..5803e89 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -149,7 +149,7 @@ class Sentinel(object): if not self.start_event.is_set() and not self.stop_event.is_set(): return Conf.STARTING elif self.start_event.is_set() and not self.stop_event.is_set(): - if self.result_queue.qsize() == 0 and self.task_queue.qsize() == 0: + if Conf.QSIZE and self.result_queue.qsize() == 0 and self.task_queue.qsize() == 0: return Conf.IDLE return Conf.WORKING elif self.stop_event.is_set() and self.start_event.is_set(): diff --git a/django_q/conf.py b/django_q/conf.py index a2b3517..0b68759 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -1,6 +1,6 @@ import logging from signal import signal -from multiprocessing import cpu_count +from multiprocessing import cpu_count, Queue from django.utils.translation import ugettext_lazy as _ from django.conf import settings @@ -63,6 +63,12 @@ class Conf(object): # The redis stats key Q_STAT = 'django_q:{}:cluster'.format(PREFIX) + # OSX doesn't implement qsize because of missing sem_getvalue() + try: + QSIZE = Queue().qsize == 0 + except NotImplementedError: + QSIZE = False + # Getting the signal names SIGNAL_NAMES = dict((getattr(signal, n), n) for n in dir(signal) if n.startswith('SIG') and '_' not in n) diff --git a/django_q/monitor.py b/django_q/monitor.py index 92bd7ff..3b001c1 100644 --- a/django_q/monitor.py +++ b/django_q/monitor.py @@ -117,10 +117,13 @@ class Stat(Status): self.reincarnations = sentinel.reincarnations self.sentinel = sentinel.pid self.status = sentinel.status() - self.done_q_size = sentinel.result_queue.qsize() + self.done_q_size = 0 + self.task_q_size = 0 + if Conf.QSIZE: + self.done_q_size = sentinel.result_queue.qsize() + self.task_q_size = sentinel.task_queue.qsize() if sentinel.monitor: self.monitor = sentinel.monitor.pid - self.task_q_size = sentinel.task_queue.qsize() if sentinel.pusher: self.pusher = sentinel.pusher.pid self.workers = [w.pid for w in sentinel.pool] diff --git a/django_q/tests/test_cluster.py b/django_q/tests/test_cluster.py index 684bb86..7d956b6 100644 --- a/django_q/tests/test_cluster.py +++ b/django_q/tests/test_cluster.py @@ -55,7 +55,8 @@ def test_cluster_initial(r): assert c.is_starting is False sleep(0.5) stat = c.stat - assert stat.status == Conf.IDLE + if Conf.QSIZE: + assert stat.status == Conf.IDLE assert c.stop() is True assert c.sentinel.is_alive() is False assert c.has_stopped