| 468 | __slots__ = ("weakref", "func", "args", "kwargs", "atexit", "index") |
| 469 | |
| 470 | def __init__(self, obj, func, /, *args, **kwargs): |
| 471 | if not self._registered_with_atexit: |
| 472 | # We may register the exit function more than once because |
| 473 | # of a thread race, but that is harmless |
| 474 | import atexit |
| 475 | atexit.register(self._exitfunc) |
| 476 | finalize._registered_with_atexit = True |
| 477 | info = self._Info() |
| 478 | info.weakref = ref(obj, self) |
| 479 | info.func = func |
| 480 | info.args = args |
| 481 | info.kwargs = kwargs or None |
| 482 | info.atexit = True |
| 483 | info.index = next(self._index_iter) |
| 484 | self._registry[self] = info |
| 485 | finalize._dirty = True |
| 486 | |
| 487 | def __call__(self, _=None): |
| 488 | """If alive then mark as dead and return func(*args, **kwargs); |