1

I am running a rather complex python script through a screen session on my server. Sometimes, after some hours, it crashes and I can’t figure out why. Since the script runs in screen, I don’t get access to the error when the scrips crashes. Is there any way to extract that info through logging or a simple pipe?

2 Answers 2

1

You can use nohup and & to run your python command in the background. The default output will log any printed outputs (including the error that terminates your script) in a nohup.out file. You can specify the file output in Bash using >

For example

nohup python my_python_script.py > my_output_log &
Sign up to request clarification or add additional context in comments.

2 Comments

that seems good. Can I run multiple scrips in paralell and different output files with this?
Yes, this should be possible. However, you will need to be careful not to mess up your nohup.out file if you stick to the default as it will just append the output to the file so you could end up with a mess.
0

I had a very similar problem and I did something like this

import logging
logging.basicConfig(filename = os.path.join(script_path, 'error.log'), level = logging.ERROR)
try:
    # some dangerous code here
except Exception as e:
    logging.exception(str(e))
    # Now you can kill your script, etc

This is going to generate a file 'error.log' with the info of the crash

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.