(
*, config: Config, prev_hook: Callable[[sys.UnraisableHookArgs], object]
)
| 84 | |
| 85 | |
| 86 | def cleanup( |
| 87 | *, config: Config, prev_hook: Callable[[sys.UnraisableHookArgs], object] |
| 88 | ) -> None: |
| 89 | class="cm"># On PyPy, objects (e.g. coroutines) can survive GC rounds because executing |
| 90 | class="cm"># their __del__ can resurrect them. The Trio project determined experimentally |
| 91 | class="cm"># that 5 passes are needed on PyPy to flush everything. On CPython, reference |
| 92 | class="cm"># counting handles most cleanup immediately, so 1 pass is sufficient. |
| 93 | _default_gc_collect_iterations = 5 if sys.implementation.name == class="st">"pypy" else 1 |
| 94 | gc_collect_iterations = config.stash.get( |
| 95 | gc_collect_iterations_key, _default_gc_collect_iterations |
| 96 | ) |
| 97 | try: |
| 98 | try: |
| 99 | gc_collect_harder(gc_collect_iterations) |
| 100 | collect_unraisable(config) |
| 101 | finally: |
| 102 | sys.unraisablehook = prev_hook |
| 103 | finally: |
| 104 | del config.stash[unraisable_exceptions] |
| 105 | |
| 106 | |
| 107 | def unraisable_hook( |
nothing calls this directly
no test coverage detected