(cls)
| 542 | |
| 543 | @classmethod |
| 544 | def _exitfunc(cls): |
| 545 | # At shutdown invoke finalizers for which atexit is true. |
| 546 | # This is called once all other non-daemonic threads have been |
| 547 | # joined. |
| 548 | reenable_gc = False |
| 549 | try: |
| 550 | if cls._registry: |
| 551 | import gc |
| 552 | if gc.isenabled(): |
| 553 | reenable_gc = True |
| 554 | gc.disable() |
| 555 | pending = None |
| 556 | while True: |
| 557 | if pending is None or finalize._dirty: |
| 558 | pending = cls._select_for_exit() |
| 559 | finalize._dirty = False |
| 560 | if not pending: |
| 561 | break |
| 562 | f = pending.pop() |
| 563 | try: |
| 564 | # gc is disabled, so (assuming no daemonic |
| 565 | # threads) the following is the only line in |
| 566 | # this function which might trigger creation |
| 567 | # of a new finalizer |
| 568 | f() |
| 569 | except Exception: |
| 570 | sys.excepthook(*sys.exc_info()) |
| 571 | assert f not in cls._registry |
| 572 | finally: |
| 573 | # prevent any more finalizers from executing during shutdown |
| 574 | finalize._shutdown = True |
| 575 | if reenable_gc: |
| 576 | gc.enable() |
nothing calls this directly
no test coverage detected