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

Function _run_finalizers

Lib/multiprocessing/util.py:339–377  ·  view source on GitHub ↗

Run all finalizers whose exit priority is not None and at least minpriority Finalizers with highest priority are called first; finalizers with the same priority will be called in reverse order of creation.

(minpriority=None)

Source from the content-addressed store, hash-verified

337
338
339def _run_finalizers(minpriority=None):
340 '''
341 Run all finalizers whose exit priority is not None and at least minpriority
342
343 Finalizers with highest priority are called first; finalizers with
344 the same priority will be called in reverse order of creation.
345 '''
346 if _finalizer_registry is None:
347 # This function may be called after this module's globals are
348 # destroyed. See the _exit_function function in this module for more
349 # notes.
350 return
351
352 if minpriority is None:
353 f = lambda p : p[0] is not None
354 else:
355 f = lambda p : p[0] is not None and p[0] >= minpriority
356
357 # Careful: _finalizer_registry may be mutated while this function
358 # is running (either by a GC run or by another thread).
359
360 # list(_finalizer_registry) should be atomic, while
361 # list(_finalizer_registry.items()) is not.
362 keys = [key for key in list(_finalizer_registry) if f(key)]
363 keys.sort(reverse=True)
364
365 for key in keys:
366 finalizer = _finalizer_registry.get(key)
367 # key may have been removed from the registry
368 if finalizer is not None:
369 sub_debug('calling %s', finalizer)
370 try:
371 finalizer()
372 except Exception:
373 import traceback
374 traceback.print_exc()
375
376 if minpriority is None:
377 _finalizer_registry.clear()
378
379#
380# Clean up on exit

Callers 2

_exit_functionFunction · 0.85
_cleanup_testsFunction · 0.85

Calls 7

listClass · 0.85
sub_debugFunction · 0.85
print_excMethod · 0.80
fFunction · 0.50
sortMethod · 0.45
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…