Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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))
Ejemplo n.º 5
0
 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))