From 6b91d1b3e050d05f1aeb3916396493886e712389 Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.dos.anjos@gmail.com> Date: Fri, 29 Apr 2016 13:10:48 +0200 Subject: [PATCH] [backend] Also clean-up zombies after each iteration --- beat/web/backend/schedule.py | 9 +++++++++ beat/web/backend/views.py | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/beat/web/backend/schedule.py b/beat/web/backend/schedule.py index 10c8fbf9c..5d9f3cbe7 100644 --- a/beat/web/backend/schedule.py +++ b/beat/web/backend/schedule.py @@ -36,6 +36,7 @@ import subprocess import logging logger = logging.getLogger(__name__) +import psutil import simplejson from django.conf import settings @@ -475,6 +476,14 @@ def work(environments, cpulimit, process, django_settings): subprocess.Popen(cmdline + [execute, str(j.pk)]) +def cleanup_zombies(): + '''Cleans-up eventual zombie subprocesses launched by the call above''' + + for child in psutil.Process().children(): + if child.status == psutil.STATUS_ZOMBIE: + child.wait() + + def resolve_process_path(): '''Returns the path to cpulimit''' diff --git a/beat/web/backend/views.py b/beat/web/backend/views.py index 49054cd88..491921621 100644 --- a/beat/web/backend/views.py +++ b/beat/web/backend/views.py @@ -46,7 +46,7 @@ from beat.core.async import resolve_cpulimit_path from .models import Environment, Worker, Queue from ..experiments.models import Experiment from . import state -from .schedule import schedule, work, worker_update +from .schedule import schedule, work, worker_update, cleanup_zombies from .schedule import find_environments, resolve_process_path @@ -59,13 +59,13 @@ class Work: cpulimit = resolve_cpulimit_path(None) process = resolve_process_path() environments = find_environments(None) - django_settings = os.environ.get('DJANGO_SETTINGS_MODULE', - 'beat.web.settings.zzz') + django_settings = os.environ.get('DJANGO_SETTINGS_MODULE') + def __call__(self): # update workers that require updates worker_update() - + cleanup_zombies() work( Work.environments, Work.cpulimit, @@ -102,7 +102,7 @@ def scheduler(request): cache_gb = int(cache['capacity-in-megabytes'] / 1024.0) # do scheduling and/or worker activity if required - if request.GET.has_key('activity'): + if settings.SCHEDULING_PANEL and request.GET.has_key('activity'): activity = request.GET['activity'] if activity in ('both', 'schedule'): -- GitLab