Follow

extremely vague Python debug question 

I understand this is super vague, but if I have a Python script that I want to run 24/7, but every so often it just stops working (but doesn't error out)...

anything I should check that I might not have thought of?

· · Web · 6 · 1 · 0

extremely vague Python debug question 

@schlink Depending on how you run this you might want to run it in the Python Debugger to see if it gives more error messages. Downside is the script will run way slower than normal.

This will do the trick:

python -m pdb script.py

Alternatively you could wrap the whole script into a try / except with a broad exception to see if that might catch anything that is being raised (but if its not raising an exception then it might not work)

extremely vague Python debug question 

@schlink You could also check to see when it stops and see if there's anything logged at the system level. It might not be anything under Python's control of when it ends. Something like dmesg could give some more clues.

extremely vague Python debug question 

@schlink Hope this helps. I don't envy you having to find these sorts of bugs, but hopefully this will bring something better to bear.

extremely vague Python debug question 

@schlink check where it's stuck by sending it a SIGINT, which translates to a KeyboardInterrupt exception that will give you a backtrace

And when you have time, consider rewriting it in Rust :rust_thinking: 😃

extremely vague Python debug question 

@schlink (don't get me wrong, Python is a very nice language for a lot of things, but maybe not for writing robust, reliable software that you want running 24/7)

extremely vague Python debug question 

@schlink do you already know if it is caused by the [input / data it operates on] or if it has something to do with the environment or time it has been running?

extremely vague Python debug question 

@schlink maybe
If Python doesn't give an error, maybe the exit code could give you a hint.

Another possible solution would be to put the code you want to run into a function and triggering it from outside. Maybe through a cronjob. But this depends on the application you want to write.

extremely vague Python debug question 

@schlink the general: dependency on services
broken filesystem pipes (e.g. keeping a file open for the entire duration of the service, and it randomly gets closed without the program being able to handle it)
i would guess that you aren't running the script with a daemon manager, and if you do, is it configured to auto-restart on crash?
Which exit code does your python script crash with?

extremely vague Python debug question 

@schlink Try to run it in interactive mode (python -i ..) in a tmux session. Then when it stops working ^C out of the script and check the (global) variables and the line number. I think you should get a first or second hint from that, but hard to tell without knowing more about the script.

Sign in to participate in the conversation
Octodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!