Add methods for cleaning up after forking

Relates to #141
This commit is contained in:
Tyler Hobbs
2014-06-12 13:08:01 -05:00
parent c277202ac9
commit cd9ff7077b
3 changed files with 20 additions and 0 deletions

View File

@@ -187,6 +187,14 @@ class Connection(object):
"""
pass
@classmethod
def handle_fork(self):
"""
Called after a forking. This should cleanup any remaining reactor state
from the parent process.
"""
pass
def close(self):
raise NotImplementedError()

View File

@@ -146,6 +146,12 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
if not cls._loop:
cls._loop = AsyncoreLoop()
@classmethod
def handle_fork(cls):
if cls._loop:
cls._loop._cleanup()
cls._loop = None
@classmethod
def factory(cls, *args, **kwargs):
timeout = kwargs.pop('timeout', 5.0)

View File

@@ -227,6 +227,12 @@ class LibevConnection(Connection):
if not cls._libevloop:
cls._libevloop = LibevLoop()
@classmethod
def handle_fork(cls):
if cls._libevloop:
cls._libevloop._cleanup()
cls._libevloop = None
@classmethod
def factory(cls, *args, **kwargs):
timeout = kwargs.pop('timeout', 5.0)