Commit 872181be authored by David Wilson's avatar David Wilson

issue #155: core: implement Side._on_fork()

Central mechanism for deleting all non-Latch file descriptors belonging
to the parent process during fork().
parent 80642ed9
......@@ -45,6 +45,7 @@ import threading
import time
import traceback
import warnings
import weakref
import zlib
# TODO: usage of 'import' after setting __name__, but before fixing up
......@@ -658,10 +659,13 @@ class LogHandler(logging.Handler):
class Side(object):
_fork_refs = weakref.WeakValueDictionary()
def __init__(self, stream, fd, cloexec=True, keep_alive=True):
self.stream = stream
self.fd = fd
self.keep_alive = keep_alive
self._fork_refs[id(self)] = self
if cloexec:
set_cloexec(fd)
set_nonblock(fd)
......@@ -674,6 +678,11 @@ class Side(object):
raise StreamError('%r.fileno() called but no FD set', self)
return self.fd
@classmethod
def _on_fork(cls):
for side in list(cls._fork_refs.values()):
side.close()
def close(self):
if self.fd is not None:
_vv and IOLOG.debug('%r.close()', self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment