Jul-25-2023, 01:34 AM
(Jul-24-2023, 01:54 PM)Gribouillis Wrote:(Jul-24-2023, 12:54 PM)Jon2222 Wrote: I find out the source code of function register:This is not the actual code of function register. For CPython, the actual code is written in C in file atexitmodule.c (see the C functionatexit_register()
in this file). So I actually replaced a function that does something by a function that does nothing.
We could replace by a function that targets more precisely the problem, for example
import atexit import functools import contextlib def register(): _atexit_register = atexit.register def register(func, *args, **kwargs): if func.__name__ == 'Exit': @functools.wraps(func) def wrapper(*args, **kwargs): with contextlib.suppress(ZeroDivisionError): return func(*args, **kwargs) _atexit_register(wrapper, *args, **kwargs) else: _atexit_register(func, *args, **kwargs) return func register.old = _atexit_register return register register = register() atexit.register = register try: from vpython import * finally: atexit.register = register.old del register
I understand this, thank you.