當前位置: 首頁>>代碼示例>>Python>>正文


Python signal.set_wakeup_fd方法代碼示例

本文整理匯總了Python中signal.set_wakeup_fd方法的典型用法代碼示例。如果您正苦於以下問題:Python signal.set_wakeup_fd方法的具體用法?Python signal.set_wakeup_fd怎麽用?Python signal.set_wakeup_fd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在signal的用法示例。


在下文中一共展示了signal.set_wakeup_fd方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def __init__(self, app, QAbstractSocket):
        self._app = app
        self.old_fd = None
        # Create a socket pair
        self.wsock, self.rsock = socketpair(type=SOCK_DGRAM)
        self.socket = QAbstractSocket(QAbstractSocket.UdpSocket, app)
        # Let Qt listen on the one end
        self.socket.setSocketDescriptor(self.rsock.fileno())
        # And let Python write on the other end
        self.wsock.setblocking(False)
        self.old_fd = signal.set_wakeup_fd(self.wsock.fileno())
        # First Python code executed gets any exception from
        # the signal handler, so add a dummy handler first
        self.socket.readyRead.connect(lambda : None)
        # Second handler does the real handling
        self.socket.readyRead.connect(self._readSignal) 
開發者ID:mherrmann,項目名稱:fbs,代碼行數:18,代碼來源:_signal.py

示例2: __init__

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def __init__(self):
        # Setup signal fd, this allows signal to behave correctly
        if os.name == 'posix':
            self.signal_pipe_r, self.signal_pipe_w = os.pipe()
            self._set_nonblock(self.signal_pipe_r)
            self._set_nonblock(self.signal_pipe_w)
            signal.set_wakeup_fd(self.signal_pipe_w)

        self._signals_received = collections.deque()

        signal.signal(signal.SIGINT, signal.SIG_DFL)
        if os.name == 'posix':
            signal.signal(signal.SIGCHLD, signal.SIG_DFL)
            signal.signal(signal.SIGTERM, self._signal_catcher)
            signal.signal(signal.SIGALRM, self._signal_catcher)
            signal.signal(signal.SIGHUP, self._signal_catcher)
        else:
            # currently a noop on window...
            signal.signal(signal.SIGTERM, self._signal_catcher)
            # FIXME(sileht): should allow to catch signal CTRL_BREAK_EVENT,
            # but we to create the child process with CREATE_NEW_PROCESS_GROUP
            # to make this work, so current this is a noop for later fix
            signal.signal(signal.SIGBREAK, self._signal_catcher) 
開發者ID:sileht,項目名稱:cotyledon,代碼行數:25,代碼來源:_utils.py

示例3: installHandler

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def installHandler(fd):
    """
    Install a signal handler which will write a byte to C{fd} when
    I{SIGCHLD} is received.

    This is implemented by installing a SIGCHLD handler that does nothing,
    setting the I{SIGCHLD} handler as not allowed to interrupt system calls,
    and using L{signal.set_wakeup_fd} to do the actual writing.

    @param fd: The file descriptor to which to write when I{SIGCHLD} is
        received.
    @type fd: C{int}
    """
    if fd == -1:
        signal.signal(signal.SIGCHLD, signal.SIG_DFL)
    else:
        def noopSignalHandler(*args):
            pass
        signal.signal(signal.SIGCHLD, noopSignalHandler)
        signal.siginterrupt(signal.SIGCHLD, False)
    return signal.set_wakeup_fd(fd) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:_signals.py

示例4: test_set_wakeup_fd_result

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def test_set_wakeup_fd_result(self):
        r1, w1 = os.pipe()
        self.addCleanup(os.close, r1)
        self.addCleanup(os.close, w1)
        r2, w2 = os.pipe()
        self.addCleanup(os.close, r2)
        self.addCleanup(os.close, w2)

        if hasattr(os, 'set_blocking'):
            os.set_blocking(w1, False)
            os.set_blocking(w2, False)

        signal.set_wakeup_fd(w1)
        self.assertEqual(signal.set_wakeup_fd(w2), w1)
        self.assertEqual(signal.set_wakeup_fd(-1), w2)
        self.assertEqual(signal.set_wakeup_fd(-1), -1) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_signal.py

示例5: test_set_wakeup_fd_blocking

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def test_set_wakeup_fd_blocking(self):
        rfd, wfd = os.pipe()
        self.addCleanup(os.close, rfd)
        self.addCleanup(os.close, wfd)

        # fd must be non-blocking
        os.set_blocking(wfd, True)
        with self.assertRaises(ValueError) as cm:
            signal.set_wakeup_fd(wfd)
        self.assertEqual(str(cm.exception),
                         "the fd %s must be in non-blocking mode" % wfd)

        # non-blocking is ok
        os.set_blocking(wfd, False)
        signal.set_wakeup_fd(wfd)
        signal.set_wakeup_fd(-1) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_signal.py

示例6: _serve_one

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def _serve_one(child_r, fds, unused_fds, handlers):
    # close unnecessary stuff and reset signal handlers
    signal.set_wakeup_fd(-1)
    for sig, val in handlers.items():
        signal.signal(sig, val)
    for fd in unused_fds:
        os.close(fd)

    (_forkserver._forkserver_alive_fd,
     semaphore_tracker._semaphore_tracker._fd,
     *_forkserver._inherited_fds) = fds

    # Run process object received over pipe
    code = spawn._main(child_r)

    return code


#
# Read and write signed numbers
# 
開發者ID:CedricGuillemet,項目名稱:Imogen,代碼行數:23,代碼來源:forkserver.py

示例7: _installHandlerUsingSetWakeup

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def _installHandlerUsingSetWakeup(fd):
    """
    Install a signal handler which will write a byte to C{fd} when
    I{SIGCHLD} is received.

    This is implemented by installing an instance of L{_Handler} wrapped
    around C{None}, setting the I{SIGCHLD} handler as not allowed to
    interrupt system calls, and using L{signal.set_wakeup_fd} to do the
    actual writing.

    @param fd: The file descriptor to which to write when I{SIGCHLD} is
        received.
    @type fd: C{int}
    """
    if fd == -1:
        signal.signal(signal.SIGCHLD, signal.SIG_DFL)
    else:
        signal.signal(signal.SIGCHLD, _Handler(None))
        siginterrupt(signal.SIGCHLD, False)
    return set_wakeup_fd(fd) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:22,代碼來源:_signals.py

示例8: handle_unix_signals

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def handle_unix_signals(self):
        if iswindows:
            # TODO: test this on windows
            self.signal_read_socket, self.signal_write_socket = socket.socketpair()
            self.signal_read_socket.setblocking(False)
            self.signal_write_socket.setblocking(False)
            read_fd, write_fd = self.signal_read_socket.fileno(), self.signal_write_socket.fileno()
        else:
            read_fd, write_fd = pipe2()
        for sig in (signal.SIGINT, signal.SIGTERM):
            signal.signal(sig, lambda x, y: None)
            signal.siginterrupt(sig, False)
        signal.set_wakeup_fd(write_fd)
        self.signal_notifier = QSocketNotifier(read_fd, QSocketNotifier.Read, self)
        self.signal_notifier.setEnabled(True)
        self.signal_notifier.activated.connect(self.signal_received, type=Qt.QueuedConnection) 
開發者ID:kovidgoyal,項目名稱:vise,代碼行數:18,代碼來源:main.py

示例9: test_set_wakeup_fd_socket_result

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def test_set_wakeup_fd_socket_result(self):
        sock1 = socket.socket()
        self.addCleanup(sock1.close)
        sock1.setblocking(False)
        fd1 = sock1.fileno()

        sock2 = socket.socket()
        self.addCleanup(sock2.close)
        sock2.setblocking(False)
        fd2 = sock2.fileno()

        signal.set_wakeup_fd(fd1)
        self.assertEqual(signal.set_wakeup_fd(fd2), fd1)
        self.assertEqual(signal.set_wakeup_fd(-1), fd2)
        self.assertEqual(signal.set_wakeup_fd(-1), -1)

    # On Windows, files are always blocking and Windows does not provide a
    # function to test if a socket is in non-blocking mode. 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:20,代碼來源:test_signal.py

示例10: activate

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def activate(self):
        """Set up signal handlers.

        On Windows this uses a QTimer to periodically hand control over to
        Python so it can handle signals.

        On Unix, it uses a QSocketNotifier with os.set_wakeup_fd to get
        notified.
        """
        self._orig_handlers[signal.SIGINT] = signal.signal(
            signal.SIGINT, self.interrupt)
        self._orig_handlers[signal.SIGTERM] = signal.signal(
            signal.SIGTERM, self.interrupt)

        if utils.is_posix and hasattr(signal, 'set_wakeup_fd'):
            # pylint: disable=import-error,no-member,useless-suppression
            import fcntl
            read_fd, write_fd = os.pipe()
            for fd in [read_fd, write_fd]:
                flags = fcntl.fcntl(fd, fcntl.F_GETFL)
                fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
            self._notifier = QSocketNotifier(typing.cast(sip.voidptr, read_fd),
                                             QSocketNotifier.Read,
                                             self)
            self._notifier.activated.connect(  # type: ignore[attr-defined]
                self.handle_signal_wakeup)
            self._orig_wakeup_fd = signal.set_wakeup_fd(write_fd)
            # pylint: enable=import-error,no-member,useless-suppression
        else:
            self._timer.start(1000)
            self._timer.timeout.connect(lambda: None)
        self._activated = True 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:34,代碼來源:crashsignal.py

示例11: deactivate

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def deactivate(self):
        """Deactivate all signal handlers."""
        if not self._activated:
            return
        if self._notifier is not None:
            assert self._orig_wakeup_fd is not None
            self._notifier.setEnabled(False)
            rfd = self._notifier.socket()
            wfd = signal.set_wakeup_fd(self._orig_wakeup_fd)
            os.close(int(rfd))
            os.close(wfd)
        for sig, handler in self._orig_handlers.items():
            signal.signal(sig, handler)
        self._timer.stop()
        self._activated = False 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:17,代碼來源:crashsignal.py

示例12: init_signals

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def init_signals(self):
        # reset signaling
        [signal.signal(s, signal.SIG_DFL) for s in self.SIGNALS]
        # init new signaling
        signal.signal(signal.SIGQUIT, self.handle_quit)
        signal.signal(signal.SIGTERM, self.handle_exit)
        signal.signal(signal.SIGINT, self.handle_quit)
        signal.signal(signal.SIGWINCH, self.handle_winch)
        signal.signal(signal.SIGUSR1, self.handle_usr1)
        signal.signal(signal.SIGABRT, self.handle_abort)

        # Don't let SIGTERM and SIGUSR1 disturb active requests
        # by interrupting system calls
        if hasattr(signal, 'siginterrupt'):  # python >= 2.6
            signal.siginterrupt(signal.SIGTERM, False)
            signal.siginterrupt(signal.SIGUSR1, False)

        if hasattr(signal, 'set_wakeup_fd'):
            signal.set_wakeup_fd(self.PIPE[1]) 
開發者ID:jpush,項目名稱:jbox,代碼行數:21,代碼來源:base.py

示例13: test_invalid_fd

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def test_invalid_fd(self):
        fd = test_support.make_bad_fd()
        self.assertRaises(ValueError, signal.set_wakeup_fd, fd) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:test_signal.py

示例14: setUp

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def setUp(self):
        import fcntl

        self.alrm = signal.signal(signal.SIGALRM, lambda x,y:None)
        self.read, self.write = os.pipe()
        flags = fcntl.fcntl(self.write, fcntl.F_GETFL, 0)
        flags = flags | os.O_NONBLOCK
        fcntl.fcntl(self.write, fcntl.F_SETFL, flags)
        self.old_wakeup = signal.set_wakeup_fd(self.write) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_signal.py

示例15: tearDown

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import set_wakeup_fd [as 別名]
def tearDown(self):
        signal.set_wakeup_fd(self.old_wakeup)
        os.close(self.read)
        os.close(self.write)
        signal.signal(signal.SIGALRM, self.alrm) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_signal.py


注:本文中的signal.set_wakeup_fd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。