Cron Finishing Python Script?

I have a "long" python script that runs approximately 45 [min]. I am using another (“scheduler” script) python script to run this long script. When I run the "scheduler" script using the terminal, everything works fine (this means that the "long" script works without any problems).

I had some struggle, but in the end I managed to add a “scheduler” script to run through cron every minute. so now it "runs" another script and works fine.

Here is the problem: whenever a script (which is run by the "scheduler") has a line that reads:

print "hello" 

or any print statement, the cron job starts, but ends after 20-30 seconds. When I delete any print statements, cron starts jobs normally and does not interrupt.

I would like to correct this situation, and the scripts continue to work, even if they have some kind of "print" expression. any clues how to do this?

PS from the "planner" I use

 subprocess.Popen([sys.executable, command]) 

to run all other python scripts.

+4
source share
1 answer

I have a suspicion that it is due to the cron method handling stdout. How do you redirect the output?

From http://aplawrence.com/BDD/bbcronbasics.html :

OUTPUT

Usually, the output of any program is sent to STDOUT (standard notification) and usually a screen is wound around someone. For the work started by cron, STDOUT will be directed to the local mail subsystem, which means any output created by the cron task will be mailed to the user who owns the work. If this is not desired, you should take steps to redirect the output of the cron job to a file. You are also prompted to redirect STDERR (standard error) to a file in order to be able to analyze any anomalies in your cron execution work.

+6
source

Source: https://habr.com/ru/post/1332789/


All Articles