Forums

Output redirection not working when running Python script via Bash

I have a Python program that's supposed to be up 24/7 that keeps terminating for some reason even though I haven't reached the limit and I want to find out the reason. But when I run it on a Bash console try doing output redirection via python myscript.py >> output.txt 2>&1, the output file always comes up empty, even though if I run it without output redirection I can see the output.

That's definitely a bit weird- do you know for example if the script may just finish running and exit? Also, do you know how frequently this happens? The console servers do get restarted periodically for maintenance (but should still give you a message that your script got killed etc)

The script is supposed to be run in an infinite loop so to there shouldn't be anything that causes it to exit. Unfortunately output redirection does not seem to work for me so I can't examine the reason. It used to happen once every 4-5 days but recently it's been happening every 1-2 days.

output redirection may have difficulties on PA due to our sandboxing constraints (/dev/tty is not available). You may be able to do some output redirection by piping to tee instead?

But that's by-the-by really, the reason your processes are killed is because we restart console servers every so often for maintenance. If you want to have a long-running task, we recommend this workaround:

https://help.pythonanywhere.com/pages/LongRunningTasks