Ejemplo n.º 1
0
    def check_sigmasks(sigmasks: psutil_extra.ProcessSignalMasks) -> None:
        if hasattr(sigmasks, "blocked"):
            assert sigmasks.blocked == signal.pthread_sigmask(
                signal.SIG_BLOCK, [])

        if hasattr(sigmasks, "pending"):
            assert sigmasks.pending == signal.sigpending()
Ejemplo n.º 2
0
        def inner():
            # Block signals unconditionally to avoid them impacting our return
            # code.
            signal.pthread_sigmask(signal.SIG_SETMASK, test_signals)
            for sig in test_signals:
                os.kill(pid, sig)

            received_signal = False
            received_signals = signal.sigpending()
            while received_signals != test_signals:
                result = signal.sigtimedwait(forwarded_signals, 0.1)
                if result is not None:
                    received_signal = True
                    received_signals.add(result.si_signo)
                elif received_signal:
                    # Only trace after the first empty response.
                    received_signal = False
                    logger.debug("Waiting for %s",
                                 test_signals - received_signals)

            output_path.write_text(to_string(received_signals),
                                   encoding="utf-8")
Ejemplo n.º 3
0
 def test_sigpending_empty(self):
     self.assertEqual(signal.sigpending(), set())
Ejemplo n.º 4
0
 def test_sigpending_empty(self):
     self.assertEqual(signal.sigpending(), set())
Ejemplo n.º 5
0
#coding:utf-8
"""
@author: mcfee
@description:阻塞信号
@file: test_signal.py
@time: 2020/6/23 下午3:45
"""
import signal
import time


def test(sign, frame):
    print("触发方法")


signal.signal(signal.SIGALRM, test)
signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGALRM])  # 设置信号屏蔽
signal.alarm(1)
time.sleep(2)
print(signal.sigpending())
signal.pthread_sigmask(signal.SIG_UNBLOCK, [signal.SIGALRM])  # 解除信号屏蔽
###解除信号屏蔽后,信号就交付了