Discussion:
Crash when launching python
(too old to reply)
Guenther Sohler
2024-09-04 15:27:40 UTC
Permalink
Hi,

My "Project" is to integrate python support into OpenSCAD. It runs quite
well, but
there are still issues on MacOS. On My MacOS it works, but it crashes when
I ship
the DMG files.
It looks very much like python is not able to find the "startup" python
files and therefore crashes.

Is it possible to turn on debugging and to display on the console, where
python is loading files from ?


Thank you
Stefan Ram
2024-09-04 15:52:28 UTC
Permalink
Post by Guenther Sohler
Is it possible to turn on debugging and to display on the console, where
python is loading files from ?
The "-v" flag? It's like a snitch for module loading. It'll spill
the beans on where each module's coming from - whether it's a file
or baked right into Python. Stack those "-v"s for the full 411.

Now, if you're feeling extra Californian, you can set the
"PYTHONVERBOSE" environment variable to some integer. It's like
hitting the "-v" button multiple times, but with that laid-back
West Coast vibe.

Oh, and get this - "sys.settrace(tracefunc)" is like the
ultimate stalker for your code. It lets you set up a trace
function that'll tail your Python source code closer than
paparazzi on Rodeo Drive. Perfect for when you wanna debug
your code like you're solving a Hollywood mystery!
Barry
2024-09-05 13:51:01 UTC
Permalink
Normally it's in the <appname>.app/Contents/MacOS subdirectory. The name
varies, but there's usually just one executable file in there. Run that
from a shell and you should see anything written to stdout or stderr.
I recall that does not always work for app code that expects the macOS options that are passed in when launching from GUI.

Barry
dn
2024-09-04 19:25:13 UTC
Permalink
Post by Guenther Sohler
Hi,
My "Project" is to integrate python support into OpenSCAD. It runs quite
well, but
there are still issues on MacOS. On My MacOS it works, but it crashes when
I ship
the DMG files.
It looks very much like python is not able to find the "startup" python
files and therefore crashes.
Is it possible to turn on debugging and to display on the console, where
python is loading files from ?
(am not a Mac user)

Starting with 'the basics', are you familiar with:
5. Using Python on a Mac https://docs.python.org/3/using/mac.html
(and the more general preceding sections)

This doc likely includes mention of such parameters:
1.2. Environment variables
https://docs.python.org/3/using/cmdline.html#environment-variables

Here is a library for programmatic manipulation:
site — Site-specific configuration hook
https://docs.python.org/3/library/site.html#module-site

Please let us know how things progress...
--
Regards,
=dn
Barry Scott
2024-09-04 19:48:21 UTC
Permalink
Post by Guenther Sohler
Is it possible to turn on debugging and to display on the console, where
python is loading files from ?
I assume you have a .app that is then packaged into a .dmg.

It will be the .app that you need to either build with a debug version of your code
or after building the .app edit the debug code into it.

Do you know that .app files are a tree of files?
You can right-click on an .app in Finder and it will have a "Show Package Context" option.

Or using the terminal and you can:
cd <appname>.app/Contents

then have a look around.

Beware that you cannot use print to stdout for a .app as its stdin/stdout do not go anywhere useful.
What I do is use code like this in the main function:

sys.stdout = open( '/home/barry/debug.log', 'w', 1 )
sys.stderr = sys.stdout

Now you can use print(); look in the debug.log to see what happened.
Also any tracebacks will end up in the debug.log.

Barry

Loading...