diff --git a/mitogen/core.py b/mitogen/core.py index 1bb4a1ee..2e43ed65 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -981,6 +981,7 @@ class Latch(object): closed = False _waking = 0 _sockets = [] + _allsockets = [] def __init__(self): self._lock = threading.Lock() @@ -989,10 +990,9 @@ class Latch(object): @classmethod def _on_fork(cls): - while cls._sockets: - rsock, wsock = cls._sockets.pop() - rsock.close() - wsock.close() + cls._sockets = [] + while cls._allsockets: + cls._allsockets.pop().close() def close(self): self._lock.acquire() @@ -1015,6 +1015,7 @@ class Latch(object): rsock, wsock = socket.socketpair() set_cloexec(rsock.fileno()) set_cloexec(wsock.fileno()) + self._allsockets.extend((rsock, wsock)) return rsock, wsock def get(self, timeout=None, block=True):