MCPcopy Index your code
hub / github.com/python/cpython / test_stress_delivery_simultaneous

Method test_stress_delivery_simultaneous

Lib/test/test_signal.py:1316–1347  ·  view source on GitHub ↗

This test uses simultaneous signal handlers.

(self)

Source from the content-addressed store, hash-verified

1314 @unittest.skipUnless(hasattr(signal, "setitimer"),
1315 "test needs setitimer()")
1316 def test_stress_delivery_simultaneous(self):
1317 """
1318 This test uses simultaneous signal handlers.
1319 """
1320 N = self.decide_itimer_count()
1321 sigs = []
1322
1323 def handler(signum, frame):
1324 sigs.append(signum)
1325
1326 # On Android, SIGUSR1 is unreliable when used in close proximity to
1327 # another signal – see Android/testbed/app/src/main/python/main.py.
1328 # So we use a different signal.
1329 self.setsig(signal.SIGUSR2, handler)
1330 self.setsig(signal.SIGALRM, handler) # for ITIMER_REAL
1331
1332 expected_sigs = 0
1333 while expected_sigs < N:
1334 # Hopefully the SIGALRM will be received somewhere during
1335 # initial processing of SIGUSR2.
1336 signal.setitimer(signal.ITIMER_REAL, 1e-6 + random.random() * 1e-5)
1337 os.kill(os.getpid(), signal.SIGUSR2)
1338
1339 expected_sigs += 2
1340 # Wait for handlers to run to avoid signal coalescing
1341 for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
1342 if len(sigs) >= expected_sigs:
1343 break
1344
1345 # All ITIMER_REAL signals should have been delivered to the
1346 # Python handler
1347 self.assertEqual(len(sigs), N, "Some signals were lost")
1348
1349 @support.requires_gil_enabled("gh-121065: test is flaky on free-threaded build")
1350 @unittest.skipIf(is_apple, "crashes due to system bug (FB13453490)")

Callers

nothing calls this directly

Calls 5

decide_itimer_countMethod · 0.95
setsigMethod · 0.95
randomMethod · 0.45
killMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected