def register(): ''' This function creates a select.poll object that can be used in the same manner as signal.pause(). The poll object returns each time a signal was received by the process. This function has to be called from the main thread. ''' global _signal_poller global _signal_read_fd if _signal_poller is not None: raise RuntimeError('register was already called') read_fd, write_fd = os.pipe() # Python c-level signal handler requires that the write end will be in # non blocking mode filecontrol.set_non_blocking(write_fd) # Set the read pipe end to non-blocking too, just in case. filecontrol.set_non_blocking(read_fd) # Prevent subproccesses we execute from inheriting the pipes. filecontrol.set_close_on_exec(write_fd) filecontrol.set_close_on_exec(read_fd) signal.set_wakeup_fd(write_fd) poller = select.poll() poller.register(read_fd, select.POLLIN) _signal_poller = poller _signal_read_fd = read_fd
def __init__(self, map): rfd, wfd = os.pipe() asyncore.file_dispatcher.__init__(self, rfd, map=map) os.close(rfd) # file_dispatcher duped it filecontrol.set_close_on_exec(self._fileno) filecontrol.set_close_on_exec(wfd) filecontrol.set_non_blocking(wfd) self._wfd = wfd
def __init__(self, host, port, sslctx=None): self._sslctx = sslctx self._host = host self._port = port self._read_fd, self._write_fd = os.pipe() filecontrol.set_non_blocking(self._read_fd) filecontrol.set_close_on_exec(self._read_fd) filecontrol.set_non_blocking(self._write_fd) filecontrol.set_close_on_exec(self._write_fd) self._socket = self._create_socket(host, port) self._poller = select.poll() self._poller.register(self._socket, select.POLLIN) self._poller.register(self._read_fd, select.POLLIN) self._pending_connections = {} self._handlers = [] # Initialize *before* starting to serve, to make it easier to test the # cleanup logic. self._next_cleanup = time.time() + self.CLEANUP_INTERVAL self._required_size = None
def __init__(self, myRead, myWrite): self._myWrite = myWrite self._myRead = myRead filecontrol.set_non_blocking(self._myWrite) filecontrol.set_non_blocking(self._myRead) self._poller = select.poll()
def test_blocking(self): with open_fd() as fd: self.assertEqual(0, filecontrol.set_non_blocking(fd, False)) self.assertFalse(os.O_NONBLOCK & fcntl.fcntl(fd, fcntl.F_GETFL))