bernhard-42 / vscode-ocp-cad-viewer

A viewer for OCP based Code-CAD (CadQuery, build123d) integrated into VS Code
Apache License 2.0
78 stars 9 forks source link

2.3.1 hangs at exit #73

Closed MatthiasJ1 closed 2 months ago

MatthiasJ1 commented 2 months ago

Pip package version: 2.3.1 vsCode extension version: v2.3.1

If I run the following file in vsCode:

import ocp_vscode
ocp_vscode.show()
print("Hello")

it will hang indefinitely. If you then press Ctrl-C:

Hello
^CException ignored in: <module 'threading' from '/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.12/threading.py'>
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/micromamba/envs/cad/lib/python3.12/threading.py", line 1622, in _shutdown
    lock.acquire()
MatthiasJ1 commented 2 months ago

This may or may not be related but I did not have the Jupyter vsCode extension installed, although this was not an issue in 2.2.2

bernhard-42 commented 2 months ago

I saw this when running the unit tests, but it didn't happen when running in VSCode. I'll try to reproduce

bernhard-42 commented 2 months ago

Found the problem. I remove closing websockets after each call (saves up to a second). However, is a big issue at the end. Need to see what I can do. Uncomment the following lines and it should behave like before:

https://github.com/bernhard-42/vscode-ocp-cad-viewer/blob/b6182c681ad86166aa6f320793ff668e1fc1f2d5/ocp_vscode/comms.py#L145-L148

bernhard-42 commented 2 months ago

For reference https://github.com/python-websockets/websockets/issues/1455

MatthiasJ1 commented 2 months ago

This feels like a hack but it may solve the issue: https://docs.python.org/3/library/atexit.html

bernhard-42 commented 2 months ago

I'll start with trying to fix the thread thing as mentioned above. But if that doesnt work, atexit is a good next step 😀

bernhard-42 commented 2 months ago

pip install --upgrade git+https://github.com/python-websockets/websockets.git@f0398141d2efd28f64d8e1d6d9adc179a9e5e334 This commit (from last week) fixes the issue. Need to check whether websockets 12.0 is compatible. But this would be the easiest fix

btw. atexit fails, since the program is waiting for the thread => no exit happens 😀

bernhard-42 commented 2 months ago

@MatthiasJ1 Could you maybe try the the pip installation of websockets on your machine? pip will complain tht ocp_vscode wants websockets 11, but that can be ignored. For me it solves the problem

MatthiasJ1 commented 2 months ago

Installing the latest released version of websockets does not fix the issue but installing the dev version from github does.

bernhard-42 commented 2 months ago

arrg, pypi doesn't allow direct links as dependencies. So, can't package this simple fix. Need to find another way

bernhard-42 commented 2 months ago

Should be fixed with v2.3.2

MatthiasJ1 commented 2 months ago

Sorry for the late reply, just confirming that it is fixed for me. Thanks for looking into this.