Commit f47dd646 authored by Julien Muchembled's avatar Julien Muchembled

Fix use of several EpollEventManager within the same process

This fixes commit 0e43dd1f
("Fix signals not always being processed as soon as possible").
parent 2f760fa5
......@@ -42,6 +42,33 @@ def nonblock(fd):
# If a process has several instances of EpollEventManager like in threaded
# tests, it does not matter which one is woke up by signals.
class WakeupFD(object):
_lock = Lock()
_fds = []
@classmethod
def add(cls, fd):
fds = cls._fds
with cls._lock:
if fds:
assert fd not in fds, (fd, fds)
else:
prev = set_wakeup_fd(fd)
assert prev == -1, (fd, prev)
fds.append(fd)
@classmethod
def remove(cls, fd):
fds = cls._fds
with cls._lock:
i = fds.index(fd)
del fds[i]
if not (i and fds):
prev = set_wakeup_fd(fds[0] if fds else -1)
assert prev == fd, (fd, prev)
class EpollEventManager(object):
"""This class manages connections and events based on epoll(5)."""
......@@ -59,8 +86,7 @@ class EpollEventManager(object):
self._wakeup_wfd = w
nonblock(r)
nonblock(w)
fd = set_wakeup_fd(w)
assert fd == -1, fd
WakeupFD.add(w)
self.epoll.register(r, EPOLLIN)
self._trigger_lock = Lock()
self.lock = l = Lock()
......@@ -79,7 +105,7 @@ class EpollEventManager(object):
self._closeRelease = release
def close(self):
set_wakeup_fd(-1)
WakeupFD.remove(self._wakeup_wfd)
os.close(self._wakeup_wfd)
os.close(self._wakeup_rfd)
for c in self.connection_dict.values():
......
......@@ -102,12 +102,6 @@ logging.default_root_handler.handle = lambda record: None
debug.register()
# XXX: Not so important and complicated to make it work in the test process
# because there may be several EpollEventManager and threads.
# We only need it in child processes so that functional tests can stop.
event.set_wakeup_fd = lambda fd, pid=os.getpid(): (
-1 if pid == os.getpid() else signal.set_wakeup_fd(fd))
def mockDefaultValue(name, function):
def method(self, *args, **kw):
if name in self.mockReturnValues:
......
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