Python Forum
I try to import Vpython and I get a "ZeroDivisionError"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I try to import Vpython and I get a "ZeroDivisionError"
#10
(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 function atexit_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.
Reply


Messages In This Thread
RE: I try to import Vpython and I get a "ZeroDivisionError" - by Jon2222 - Jul-25-2023, 01:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ZeroDivisionError laurawoods 1 343 Apr-11-2024, 03:27 AM
Last Post: deanhystad
  Overcoming ZeroDivisionError: division by zero Error dgrunwal 8 5,249 Jun-12-2020, 01:52 PM
Last Post: dgrunwal
  ZeroDivisionError CIVILmath 2 2,598 Jan-17-2019, 02:38 AM
Last Post: CIVILmath
  Vpython Delay in plotting points SohaibAJ 0 2,123 Jul-30-2018, 08:44 PM
Last Post: SohaibAJ
  Anaconda / Spyder / VPython mwatson87 3 108,801 May-24-2018, 01:51 PM
Last Post: snippsat
  VPython - Trying to make orbit simulation totalnoob 2 5,722 Sep-13-2017, 03:59 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020