Home | History | Annotate | Download | only in test

Lines Matching full:signal

8 import signal
29 for name in dir(signal):
30 sig = getattr(signal, name)
32 self.assertIsInstance(sig, signal.Handlers)
34 self.assertIsInstance(sig, signal.Sigmasks)
36 self.assertIsInstance(sig, signal.Signals)
38 self.assertIsInstance(sig, signal.Signals)
48 self.assertRaises(ValueError, signal.getsignal, 4242)
50 self.assertRaises(ValueError, signal.signal, 4242,
54 self.assertRaises(TypeError, signal.signal,
55 signal.SIGUSR1, None)
58 hup = signal.signal(signal.SIGHUP, self.trivial_signal_handler)
59 self.assertIsInstance(hup, signal.Handlers)
60 self.assertEqual(signal.getsignal(signal.SIGHUP),
62 signal.signal(signal.SIGHUP, hup)
63 self.assertEqual(signal.getsignal(signal.SIGHUP), hup)
81 for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
82 signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
83 signal.SIGTERM):
86 if signal.getsignal(sig) is not None:
87 signal.signal(sig, signal.signal(sig, handler))
93 signal.signal(-1, handler)
96 signal.signal(7, handler)
104 signal.set_wakeup_fd, fd)
111 signal.set_wakeup_fd, fd)
125 signal.set_wakeup_fd(w1)
126 self.assertEqual(signal.set_wakeup_fd(w2), w1)
127 self.assertEqual(signal.set_wakeup_fd(-1), w2)
128 self.assertEqual(signal.set_wakeup_fd(-1), -1)
141 signal.set_wakeup_fd(fd1)
142 self.assertEqual(signal.set_wakeup_fd(fd2), fd1)
143 self.assertEqual(signal.set_wakeup_fd(-1), fd2)
144 self.assertEqual(signal.set_wakeup_fd(-1), -1)
157 signal.set_wakeup_fd(wfd)
163 signal.set_wakeup_fd(wfd)
164 signal.set_wakeup_fd(-1)
175 import signal
194 signal.signal(signal.SIGALRM, handler)
197 signal.set_wakeup_fd(write)
210 # Issue #16105: write() errors in the C signal handler should not
217 import signal
224 signal.signal(signal.SIGALRM, handler)
229 signal.set_wakeup_fd(r)
232 _testcapi.raise_signal(signal.SIGALRM)
236 if ('Exception ignored when trying to write to the signal wakeup fd'
273 signal.signal(signal.SIGALRM, handler)
275 signal.alarm(1)
277 # We attempt to get a signal during the sleep,
292 """, signal.SIGALRM)
307 signal.signal(signal.SIGALRM, handler)
309 signal.alarm(1)
311 # We attempt to get a signal during the select call
322 """, signal.SIGALRM)
327 signal.signal(signal.SIGUSR1, handler)
328 _testcapi.raise_signal(signal.SIGUSR1)
329 _testcapi.raise_signal(signal.SIGALRM)
330 """, signal.SIGUSR1, signal.SIGALRM)
332 @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
333 'need signal.pthread_sigmask()')
336 signum1 = signal.SIGUSR1
337 signum2 = signal.SIGUSR2
339 signal.signal(signum1, handler)
340 signal.signal(signum2, handler)
342 signal.pthread_sigmask(signal.SIG_BLOCK, (signum1, signum2))
345 # Unblocking the 2 signals calls the C signal handler twice
346 signal.pthread_sigmask(signal.SIG_UNBLOCK, (signum1, signum2))
347 """, signal.SIGUSR1, signal.SIGUSR2, ordered=False)
357 import signal
362 signum = signal.SIGINT
368 signal.signal(signum, handler)
373 signal.set_wakeup_fd(write.fileno())
399 import signal
406 signum = signal.SIGINT
411 signal.signal(signum, handler)
417 signal.set_wakeup_fd(write.fileno())
427 if ('Exception ignored when trying to {action} to the signal wakeup fd'
438 """Perform a read during which a signal will arrive. Return True if the
439 read is interrupted by the signal and raises an exception. Return False
443 # blocking read and to not touch signal handling in this process
447 import signal
456 signal.signal(signal.SIGALRM, handler)
458 signal.siginterrupt(signal.SIGALRM, interrupt)
467 signal.alarm(1)
498 # If a signal handler is installed and siginterrupt is not called
499 # at all, when that signal arrives, it interrupts a syscall that's in
505 # If a signal handler is installed and siginterrupt is called with
506 # a true value for the second argument, when that signal arrives, it
512 # If a signal handler is installed and siginterrupt is called with
513 # a false value for the second argument, when that signal arrives, it
525 self.old_alarm = signal.signal(signal.SIGALRM, self.sig_alrm)
528 signal.signal(signal.SIGALRM, self.old_alarm)
531 signal.setitimer(self.itimer, 0)
541 raise signal.ItimerError("setitimer didn't disable ITIMER_VIRTUAL "
545 signal.setitimer(signal.ITIMER_VIRTUAL, 0)
551 signal.setitimer(signal.ITIMER_PROF, 0)
556 self.assertRaises(signal.ItimerError, signal.setitimer, -1, 0)
559 self.assertRaises(signal.ItimerError,
560 signal.setitimer, signal.ITIMER_REAL, -1)
563 self.itimer = signal.ITIMER_REAL
564 signal.setitimer(self.itimer, 1.0)
565 signal.pause()
572 self.itimer = signal.ITIMER_VIRTUAL
573 signal.signal(signal.SIGVTALRM, self.sig_vtalrm)
574 signal.setitimer(self.itimer, 0.3, 0.2)
580 if signal.getitimer(self.itimer) == (0.0, 0.0):
587 self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
595 self.itimer = signal.ITIMER_PROF
596 signal.signal(signal.SIGPROF, self.sig_prof)
597 signal.setitimer(self.itimer, 0.2, 0.2)
603 if signal.getitimer(self.itimer) == (0.0, 0.0):
610 self.assertEqual(signal.getitimer(self.itimer), (0.0, 0.0))
620 @unittest.skipUnless(hasattr(signal, 'sigpending'),
621 'need signal.sigpending()')
623 self.assertEqual(signal.sigpending(), set())
625 @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
626 'need signal.pthread_sigmask()')
627 @unittest.skipUnless(hasattr(signal, 'sigpending'),
628 'need signal.sigpending()')
632 import signal
637 signum = signal.SIGUSR1
638 signal.signal(signum, handler)
640 signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
642 pending = signal.sigpending()
644 assert isinstance(sig, signal.Signals), repr(pending)
648 signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
656 @unittest.skipUnless(hasattr(signal, 'pthread_kill'),
657 'need signal.pthread_kill()')
660 import signal
664 signum = signal.SIGUSR1
669 signal.signal(signum, handler)
672 # Issue #12392 and #12469: send a signal to the main thread
683 signal.pthread_kill(tid, signum)
691 @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
692 'need signal.pthread_sigmask()')
696 blocked: number of the blocked signal
699 import signal
701 from signal import Signals
709 signum = signal.SIGALRM
711 # child: block and wait the signal
713 signal.signal(signum, handler)
714 signal.pthread_sigmask(signal.SIG_BLOCK, [blocked])
721 signal.pthread_sigmask(signal.SIG_UNBLOCK, [blocked])
723 print("the signal handler has been called",
732 # sig*wait* must be called with the signal blocked: since the current
737 @unittest.skipUnless(hasattr(signal, 'sigwait'),
738 'need signal.sigwait()')
740 self.wait_helper(signal.SIGALRM, '''
742 signal.alarm(1)
743 received = signal.sigwait([signum])
744 assert isinstance(received, signal.Signals), received
749 @unittest.skipUnless(hasattr(signal, 'sigwaitinfo'),
750 'need signal.sigwaitinfo()')
752 self.wait_helper(signal.SIGALRM, '''
754 signal.alarm(1)
755 info = signal.sigwaitinfo([signum])
760 @unittest.skipUnless(hasattr(signal, 'sigtimedwait'),
761 'need signal.sigtimedwait()')
763 self.wait_helper(signal.SIGALRM, '''
765 signal.alarm(1)
766 info = signal.sigtimedwait([signum], 10.1000)
771 @unittest.skipUnless(hasattr(signal, 'sigtimedwait'),
772 'need signal.sigtimedwait()')
775 self.wait_helper(signal.SIGALRM, '''
779 info = signal.sigtimedwait([signum], 0)
784 @unittest.skipUnless(hasattr(signal, 'sigtimedwait'),
785 'need signal.sigtimedwait()')
787 self.wait_helper(signal.SIGALRM, '''
789 received = signal.sigtimedwait([signum], 1.0)
794 @unittest.skipUnless(hasattr(signal, 'sigtimedwait'),
795 'need signal.sigtimedwait()')
797 signum = signal.SIGALRM
798 self.assertRaises(ValueError, signal.sigtimedwait, [signum], -1.0)
800 @unittest.skipUnless(hasattr(signal, 'sigwait'),
801 'need signal.sigwait()')
802 @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
803 'need signal.pthread_sigmask()')
811 import os, threading, sys, time, signal
814 signum = signal.SIGUSR1
821 # the signal must be blocked by all the threads
822 signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
825 received = signal.sigwait([signum])
831 # unblock the signal, which should have been cleared by sigwait()
832 signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
835 @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
836 'need signal.pthread_sigmask()')
838 self.assertRaises(TypeError, signal.pthread_sigmask)
839 self.assertRaises(TypeError, signal.pthread_sigmask, 1)
840 self.assertRaises(TypeError, signal.pthread_sigmask, 1, 2, 3)
841 self.assertRaises(OSError, signal.pthread_sigmask, 1700, [])
843 @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
844 'need signal.pthread_sigmask()')
847 import signal
858 assert isinstance(sig, signal.Signals), repr(sig)
861 sigmask = signal.pthread_sigmask(signal.SIG_BLOCK, [])
865 signum = signal.SIGUSR1
867 # Install our signal handler
868 old_handler = signal.signal(signum, handler)
870 # Unblock SIGUSR1 (and copy the old mask) to test our signal handler
871 old_mask = signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
880 # Block and then raise SIGUSR1. The signal is blocked: the signal
881 # handler is not called, and the signal is now pending
882 mask = signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
896 # unblock the pending signal calls immediately the signal handler
897 signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
921 "issue #12392: send a signal to the main thread doesn't work "
923 @unittest.skipUnless(hasattr(signal, 'pthread_kill'),
924 'need signal.pthread_kill()')
926 # Test that a signal can be sent to the main thread with pthread_kill()
930 import signal
936 signal.signal(signal.SIGUSR1, handler)
937 signal.pthread_kill(threading.get_ident(), signal.SIGUSR1)