ZeroDivisionError

114 views
Skip to first unread message

F. Chung (F.C.)

unread,
Jan 12, 2023, 3:48:57 PM1/12/23
to VPython-users
Hello,

I just installed vpython successfully to use with vscode.   The simple code below
produces an error as per below:

       import vpython as vp
       print(f'vPython version: {vp.__version__}')

       vPython version: 7.6.4
       exit
       Exception ignored in atexit callback: <function Exit at 0x000002CC48EB0400>
       Traceback (most recent call last):
        File "C:\CompLang\Python\Python311\Lib\site-packages\vpython\vpython.py", line          22, in Exit
        a = 1.0/zero
        ~~~^~~~~
        ZeroDivisionError: float division by zero


Is this a know issue for vPython 7?

Thanks
Felix


Bruce Sherwood

unread,
Jan 13, 2023, 12:37:43 PM1/13/23
to VPython-users
It's not VPython that's giving the error. Python gives an error when you divide by zero.

I'll mention that in Web VPython, which compiles to JavaScript, division by zero does NOT cause an error. JavaScript 1/0 gives a special object "Infinity".

Bruce

Don Hewitt

unread,
Feb 11, 2023, 11:42:23 PM2/11/23
to VPython-users
I may also be seeing the error reported by F. Chung, and I get it every time a program exits after importing vpython.
My environment is MacOS Monterrey and Pycharm with Python 3.10, and I've not tried this in other environments.

A trival program consisting of only this import statement will cause the error:
import vpython as vp

and I see the error whenever my vpython programs exit - whether due runtime errors, normally ending a program (either running out of statements or using the python exit command) or by closing the vpython browser window.

It appears that the import of vpython starts its execution engine which seems to only be able stop by causing this divide by zero exception.

I believe I've traced the problem to the Exit() function in vpython.py:

def Exit():
zero = 0.
print('exit')
a = 1.0/zero

import atexit
atexit.register(Exit)

It's possible that this is intentional (but somewhat cryptic) in order to ensure the shut down the entire runtime architecture of vpython.
For me, this is only a minor annoyance, but it doesn't seem likely to be the intended functionality of Exit()!

Don

On Friday, January 13, 2023 at 11:37:43 AM UTC-6 bruce

Bruce Sherwood

unread,
Feb 12, 2023, 11:53:08 AM2/12/23
to VPython-users
I'm not sure whether this is relevant, but here is part of the installation instructions at vpython.org:

When running from a terminal, if the program does not end with a loop
containing a rate() statement, you need to add "while True: rate(30)"
to the end of the program. This is not necessary when launching from
environments such as Jupyter notebook, IDLE, or Spyder.
Reply all
Reply to author
Forward
0 new messages