Error run in local laptop

15 views
Skip to first unread message

Ping JIA

unread,
Oct 19, 2022, 8:42:28 AM10/19/22
to glowscri...@googlegroups.com
Hello there. Here comes my problem.

I can run the following program in WebPython(GlowScript.com) but when i run in my own computer, something wrong.

=====Here is code=====
Web VPython 3.2

cube= box()
def xShift(s):
   cube.pos.x = s.value
   xs_capaction.text = "x = " + "{:1.2f}".format(xs.value) + "\n\n"
xs = slider(bind=xShift,min=-5,max=5,value = 0)
xs_capaction = wtext(text = "x = " + "{:1.2f}".format(xs.value) + "\n\n") 

===== Code end=====

When I run the program in my own mac installed vpython, it show some error.
=====Here is code=====
from vpython import *

cube= box()
def xShift(s):
   cube.pos.x = s.value
   xs_capaction.text = "x = " + "{:1.2f}".format(xs.value) + "\n\n"
xs = slider(bind=xShift,min=-5,max=5,value = 0)
xs_capaction = wtext(text = "x = " + "{:1.2f}".format(xs.value) + "\n\n")

===== Code end=====

Error message shows as follows:

===== Error Msg =====
Task exception was never retrieved
future: <Task finished name='Task-140' coro=<WSserver.onMessage() done, defined at /Users/abd/Documents/vpython/vpenv/lib/python3.9/site-packages/vpython/no_notebook.py:181> exception=RuntimeError("can't register atexit after shutdown")>

===== Msg =====

Does someone know how to fix it and run successfully in my own computer?

Steve Spicklemire

unread,
Oct 19, 2022, 10:26:40 AM10/19/22
to glowscri...@googlegroups.com, Steve Spicklemire
Hello Ping,

Can you say, what version of VPython do you have installed? I do not see the error you posted when I run the current release VPython-7.6.4. However when I *stop* the program I see:

exit
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Users/steve/vpnew/lib/python3.9/site-packages/vpython/vpython.py", line 22, in Exit
a = 1.0/zero
ZeroDivisionError: float division by zero

But my recollection is that this is a deliberate error so the program will exit without requiring one to kill the terminal on some systems.

In other words, if you see this, it’s not exactly an “error”, though it may seem like one!

-Steve
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/glowscript-users/CAK%3DJrZ6sizgg2zEXt_1kSwkDatzu2QWcsMjQer2bDFQTztwMEQ%40mail.gmail.com.

Bruce Sherwood

unread,
Oct 19, 2022, 12:33:57 PM10/19/22
to Glowscript Users
I don't see any errors at all when running from IDLE or Spyder. But I do indeed see the error when running from the terminal. There is a fix: add "while True: rate(30)" to the end of your program. This is needed only when running from the terminal.

Bruce

Bruce Sherwood

unread,
Oct 19, 2022, 12:39:38 PM10/19/22
to Glowscript Users
I'll add that when you run in Web VPython you ARE running in your own computer. Both the transpiling from Python to JavaScript and the execution of the JavaScript code are done in your browser. The cloud is used only to save and retrieve your code. Here is an overview of the architecture of VPython:


Bruce

Bruce Sherwood

unread,
Oct 19, 2022, 2:48:48 PM10/19/22
to Glowscript Users
I've added this to 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.

Ping JIA

unread,
Oct 19, 2022, 8:27:16 PM10/19/22
to glowscri...@googlegroups.com
Thanks for Steve Spicklemire and Prof. Bruce.

My program was run in terminal.  I used sublime to write code and run it in terminal. 

As Prof. Bruce suggested, after added "
while True: rate(30)", the program run successfully. Thanks

====== Code run successfully =====
from vpython import *

cube= box()
def xShift(s):
   cube.pos.x = s.value
   xs_capaction.text = "x = " + "{:1.2f}".format(xs.value) + "\n\n"
xs = slider(bind=xShift,min=-5,max=5,value = 0)
xs_capaction = wtext(text = "x = " + "{:1.2f}".format(xs.value) + "\n\n")

while True:
   rate(10)

====== code ends =====

Thanks for solving.

Bruce Sherwood <bruce.s...@gmail.com> 于2022年10月20日周四 02:48写道:
--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages