(self)
| 426 | |
| 427 | @unittest.expectedFailure # TODO: RUSTPYTHON; ctypes.pythonapi is not supported |
| 428 | def test_finalize_running_thread(self): |
| 429 | # Issue 1402: the PyGILState_Ensure / _Release functions may be called |
| 430 | # very late on python exit: on deallocation of a running thread for |
| 431 | # example. |
| 432 | if support.check_sanitizer(thread=True): |
| 433 | # the thread running `time.sleep(100)` below will still be alive |
| 434 | # at process exit |
| 435 | self.skipTest("TSAN would report thread leak") |
| 436 | import_module("ctypes") |
| 437 | |
| 438 | rc, out, err = assert_python_failure("-c", """if 1: |
| 439 | import ctypes, sys, time, _thread |
| 440 | |
| 441 | # This lock is used as a simple event variable. |
| 442 | ready = _thread.allocate_lock() |
| 443 | ready.acquire() |
| 444 | |
| 445 | # Module globals are cleared before __del__ is run |
| 446 | # So we save the functions in class dict |
| 447 | class C: |
| 448 | ensure = ctypes.pythonapi.PyGILState_Ensure |
| 449 | release = ctypes.pythonapi.PyGILState_Release |
| 450 | def __del__(self): |
| 451 | state = self.ensure() |
| 452 | self.release(state) |
| 453 | |
| 454 | def waitingThread(): |
| 455 | x = C() |
| 456 | ready.release() |
| 457 | time.sleep(100) |
| 458 | |
| 459 | _thread.start_new_thread(waitingThread, ()) |
| 460 | ready.acquire() # Be sure the other thread is waiting. |
| 461 | sys.exit(42) |
| 462 | """) |
| 463 | self.assertEqual(rc, 42) |
| 464 | |
| 465 | def test_finalize_with_trace(self): |
| 466 | # Issue1733757 |
nothing calls this directly
no test coverage detected