service: recreate the pool after fork.

pull/262/head
David Wilson 7 years ago
parent ae20a689ef
commit 3909cb11f6

@ -42,6 +42,7 @@ from mitogen.core import LOG
DEFAULT_POOL_SIZE = 16 DEFAULT_POOL_SIZE = 16
_pool = None _pool = None
_pool_pid = None
#: Serialize pool construction. #: Serialize pool construction.
_pool_lock = threading.Lock() _pool_lock = threading.Lock()
@ -49,10 +50,12 @@ _pool_lock = threading.Lock()
@mitogen.core.takes_router @mitogen.core.takes_router
def get_or_create_pool(size=None, router=None): def get_or_create_pool(size=None, router=None):
global _pool global _pool
global _pool_pid
_pool_lock.acquire() _pool_lock.acquire()
try: try:
if _pool is None: if _pool_pid != os.getpid():
_pool = Pool(router, [], size=size or DEFAULT_POOL_SIZE) _pool = Pool(router, [], size=size or DEFAULT_POOL_SIZE)
_pool_pid = os.getpid()
return _pool return _pool
finally: finally:
_pool_lock.release() _pool_lock.release()
@ -435,6 +438,8 @@ class Pool(object):
thread.start() thread.start()
self._threads.append(thread) self._threads.append(thread)
LOG.debug('%r: initialized', self)
@property @property
def size(self): def size(self):
return len(self._threads) return len(self._threads)

Loading…
Cancel
Save