gsohler / openscad

OpenSCAD - The Programmers Solid 3D CAD Modeller
https://www.openscad.org
Other
14 stars 6 forks source link

pdb.set_trace() causes a hang #16

Open gandrewstone opened 4 months ago

gandrewstone commented 4 months ago

Describe the bug

The code below hangs the whole program. It would be awesome if the console was interactive. However, that is a big ask. For now, it would be nice if it pdb.set_trace() became a no-op.

To Reproduce

# This is a http://pythonscad.org/ file
from openscad import *
import pdb
print("test")
pdb.set_trace()
print("test2")
gsohler commented 4 months ago

The Hang happens because pdb waits for input and nobody provides. Yet already I redirect python output to have it displayed in the console. I believe if python ran in an extra thread, openscad did not hang. If I additionally redirected an input field below the console into stdin of python, it would probably work ... But debugging pythonscad script is not as simple as you think, because for use with customizer sometimes the python script is run twice and you won't see any output either until your complete script has run. I don't see big demand to have pdb working with pythonscad but I am happy to accept PR's for working solutions :)

My personal debugging strategy is not setting breakpoints, but to put multiple print statements into the code and watch them in the console. Let me know what you think :)

gandrewstone commented 4 months ago

I think that for now just block the feature. I think you could create your own fake "pdb" module that would be imported in preference to the normal one and just have it's APIs print something like "interactive debug is not available". That's better then a hang (esp if you haven't saved your work!)

gsohler commented 4 months ago

Sorry, I don't have an idea how to create fake python modules which are preferred over the system one's However, the problem is much more generic: any python script which does not finish within short time, will hang openscad (pdb will not because it waits for input) So I prefer a more generic solution instead of creating fake modules. Don't be so afraid from losing unsaved work. even if you dont explicitely safe before each render, openscad will save your editor content in a backup file.