From bc4783efacb6806c26c1513a97590effbbbd2bd7 Mon Sep 17 00:00:00 2001 From: lagos Date: Thu, 27 Sep 2012 01:26:04 -0700 Subject: [PATCH] Make procpool compatible with windows and OS X. --- contrib/procpools/ampoule/main.py | 3 ++- contrib/procpools/python_procpool_plugin.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/contrib/procpools/ampoule/main.py b/contrib/procpools/ampoule/main.py index 9aec2817a4..993264ca3d 100644 --- a/contrib/procpools/ampoule/main.py +++ b/contrib/procpools/ampoule/main.py @@ -278,7 +278,8 @@ def spawnProcess(processProtocol, bootstrap, args=(), env={}, pythonpath = [] for pkg in packages: - p = os.path.split(imp.find_module(pkg)[1])[0] + path, name = os.path.split(pkg) + p = os.path.split(imp.find_module(name, [path] if path else None)[1])[0] if p.startswith(os.path.join(sys.prefix, 'lib')): continue pythonpath.append(p) diff --git a/contrib/procpools/python_procpool_plugin.py b/contrib/procpools/python_procpool_plugin.py index 337b47b5f0..d13447e661 100644 --- a/contrib/procpools/python_procpool_plugin.py +++ b/contrib/procpools/python_procpool_plugin.py @@ -24,6 +24,7 @@ file locking clashes. Test what works with your mileage. """ import os +import sys from django.conf import settings @@ -85,21 +86,20 @@ def start_plugin_services(server): apackages = ("twisted", os.path.join(os.pardir, "contrib", "procpools", "ampoule"), os.path.join(os.pardir, "ev"), - os.path.join(os.pardir)) + "settings") aenv = {"DJANGO_SETTINGS_MODULE":"settings", "DATABASE_NAME":settings.DATABASES.get("default", {}).get("NAME") or settings.DATABASE_NAME} if PROCPOOL_DEBUG: _BOOTSTRAP = _BOOTSTRAP % "log.startLogging(sys.stderr)" else: _BOOTSTRAP = _BOOTSTRAP % "" - procpool_starter = ampoule_main.ProcessStarter(packages=apackages, env=aenv, path=PROCPOOL_DIRECTORY, uid=PROCPOOL_UID, gid=PROCPOOL_GID, bootstrap=_BOOTSTRAP, - childReactor=os.name == 'nt' and "select" or "epoll") + childReactor=sys.platform == 'linux2' and "epoll" or "default") procpool = ampoule_pool.ProcessPool(name=SERVICE_NAME, min=PROCPOOL_MIN_NPROC, max=PROCPOOL_MAX_NPROC,