From 3909cb11f624a4fde6b18b8a102467602f0395ce Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 10 Jun 2018 00:57:14 +0100 Subject: [PATCH] service: recreate the pool after fork. --- mitogen/service.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mitogen/service.py b/mitogen/service.py index 811791b6..3e05deb7 100644 --- a/mitogen/service.py +++ b/mitogen/service.py @@ -42,6 +42,7 @@ from mitogen.core import LOG DEFAULT_POOL_SIZE = 16 _pool = None +_pool_pid = None #: Serialize pool construction. _pool_lock = threading.Lock() @@ -49,10 +50,12 @@ _pool_lock = threading.Lock() @mitogen.core.takes_router def get_or_create_pool(size=None, router=None): global _pool + global _pool_pid _pool_lock.acquire() try: - if _pool is None: + if _pool_pid != os.getpid(): _pool = Pool(router, [], size=size or DEFAULT_POOL_SIZE) + _pool_pid = os.getpid() return _pool finally: _pool_lock.release() @@ -435,6 +438,8 @@ class Pool(object): thread.start() self._threads.append(thread) + LOG.debug('%r: initialized', self) + @property def size(self): return len(self._threads)