vpython / vpython-jupyter

3D visualization made easy
MIT License
138 stars 65 forks source link

RuntimeError: can't register atexit after shutdown #204

Open jaguar36 opened 2 years ago

jaguar36 commented 2 years ago

When running a simple vpython script, as I move the mouse across the screen I get a continual stream of these errors:

Task exception was never retrieved
future: <Task finished name='Task-2435' coro=<WSserver.onMessage() done, defined at C:\Users\kg604c\AppData\Roaming\Python\Python310\site-packages\vpython\no_notebook.py:181> exception=RuntimeError("can't register atexit after shutdown")>
Traceback (most recent call last):
  File "C:\Users\kg604c\AppData\Roaming\Python\Python310\site-packages\vpython\no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 808, in run_in_executor
    executor = concurrent.futures.ThreadPoolExecutor(
  File "C:\Program Files\Python310\lib\concurrent\futures\__init__.py", line 49, in __getattr__
    from .thread import ThreadPoolExecutor as te
  File "C:\Program Files\Python310\lib\concurrent\futures\thread.py", line 37, in <module>
    threading._register_atexit(_python_exit)
  File "C:\Program Files\Python310\lib\threading.py", line 1484, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

This seems to be the same issue as mentioned in #133 however that was a few years ago. I'm unable to downgrade to an older version of python though, is it still something that hasn't been fixed?

I'm running Python 3.10.0 and VPython 7.6.3

BruceSherwood commented 2 years ago

Never having seen this bug, what platform are you using? What is the "simple" program that triggers the error?

jaguar36 commented 2 years ago

Windows 10 version 20H2, on either Firefox or Edge.

from vpython import *

box()
jaguar36 commented 2 years ago

bump Anyone have any suggestions? I've tried updating all the other modules that Vpython seems to use but am still getting this error.

I'm still able to manipulate the view, however widgets and buttons don't work.

BruceSherwood commented 2 years ago

I happen to be running VPython 7.6.3 with Python 3.9.7, so I will update to 3.10 to see if I can reproduce the error. Thanks for the info.

jaguar36 commented 2 years ago

I was able to find another install on the same PC with 3.7 and didn't have any issues with it. That was using a different set of modules though so I'm not sure if it is soley 3.10 that is the issue. Also seems odd that the previous poster had the same issue with 3.9 in 2020 but you said it works fine on 3.9 now.

BruceSherwood commented 2 years ago

John Coady posted the following to the VPython forum, which looks relevant:

The fix is to install an older version of autobahn package and txaio. The steps to fix are to uninstall autobahn and txaio

conda uninstall autobahn
conda uninstall txaio

or

pip uninstall autobahn
pip uninstall txaio

Then install autobahn version 21.11.1

pip install autobahn==21.11.1

and this will install txaio version 22.2.1

These were the versions of autobahn and txaio that existed when vpython 7.6.3 came out.

Vpython should probably create a new release to fix this problem or to use older versions of autobahn and txaio as dependencies.

John

jaguar36 commented 2 years ago

I tried that, but it unfortunately it didn't fix it. I also tried uninstalling all of my python modules listed by pip freeze, and then reinstalling Vpython. This gave me the error about not calling .use_twisted. Going back to the old version of autobahn fixed that.

I did add this based on another comment:

while True:
    pass

and that seems to have fixed it.

Will that cause any other issues?

BruceSherwood commented 2 years ago

I have no idea why that loop was relevant, but should you ever wish to run in jupyter notebook or jupyter lab or Web VPython I think the display will freeze (I know for sure it will freeze in Web VPython). Instead of "pass" use "rate(100)" or similar statement. It happens that of all the various instantiations of VPython, only the "no-notebook" version uses threads, which means that displays can be updated (associated with mousing, for example).