From 3b8199cb8f42fa592d4221d51191d471cc66b005 Mon Sep 17 00:00:00 2001 From: yannpom Date: Mon, 5 Dec 2016 12:21:41 +0100 Subject: [PATCH 1/3] set daemon to False --- django_q/cluster.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django_q/cluster.py b/django_q/cluster.py index ccdf93f..f2b4e62 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -147,6 +147,7 @@ class Sentinel(object): p = Process(target=target, args=args) p.daemon = True if target == worker: + p.daemon = False p.timer = args[2] self.pool.append(p) p.start() From aa667b40d43a9ae4b8ffaa41e5c6069e4daefc24 Mon Sep 17 00:00:00 2001 From: Yann Pomarede Date: Mon, 5 Dec 2016 14:55:42 +0100 Subject: [PATCH 2/3] daemonize_workers option --- django_q/cluster.py | 2 +- django_q/conf.py | 3 +++ docs/configure.rst | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index f2b4e62..a22b166 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -147,7 +147,7 @@ class Sentinel(object): p = Process(target=target, args=args) p.daemon = True if target == worker: - p.daemon = False + p.daemon = Conf.DAEMINIZE_WORKER p.timer = args[2] self.pool.append(p) p.start() diff --git a/django_q/conf.py b/django_q/conf.py index 9b7f83a..9bfbe71 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -91,6 +91,9 @@ class Conf(object): # sensible default WORKERS = 4 + # Option to undaemonize the workers and allow them to spawn child processes + DAEMONIZE_WORKERS = conf.get('daemonize_workers', True) + # Maximum number of tasks that each cluster can work on QUEUE_LIMIT = conf.get('queue_limit', int(WORKERS) ** 2) diff --git a/docs/configure.rst b/docs/configure.rst index 714881a..08e94ab 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -40,6 +40,12 @@ workers The number of workers to use in the cluster. Defaults to CPU count of the current host, but can be set to a custom number. [#f1]_ +daemonize_workers +~~~~~~~~~~~~~~~~~ + +Set the daemon flag when spawning workers. You may need to disable this flag if your worker needs to spawn child process but be carefull with orphaned child processes in case of sudden termination of the main process. +Defaults to ``True``. + recycle ~~~~~~~ From 78b997e88f9e7450518e6c8d284f3c889840c810 Mon Sep 17 00:00:00 2001 From: Yann Pomarede Date: Mon, 5 Dec 2016 14:58:42 +0100 Subject: [PATCH 3/3] fix typo --- django_q/cluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index a22b166..3810b15 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -147,7 +147,7 @@ class Sentinel(object): p = Process(target=target, args=args) p.daemon = True if target == worker: - p.daemon = Conf.DAEMINIZE_WORKER + p.daemon = Conf.DAEMONIZE_WORKERS p.timer = args[2] self.pool.append(p) p.start()