3

I have a python program that uses the ThreadPool for multithreading. The program is one step in a shell script. When I execute the shell script manually on the command line, the entire flow works as expected. However, when I execute the shell script as a cronjob, it appears that the flow goes to the next steps before the python multithreading steps are completely finished.

Inside the python program, I do call AsyncResult.get(timeout) to wait for all the results to come back before moving on.

Community
  • 1
  • 1
poiuy
  • 500
  • 5
  • 12

2 Answers2

0

Try setting "TERM=xterm" (or whatever env variable you have, figure out by command 'env' on your terminal) in your crontab.

Corentin Pane
  • 4,794
  • 1
  • 12
  • 29
vp9031
  • 71
  • 2
0

Run your program via batch(1) (see the output of the command man batch) as well. If that works OK, but the cron version does not, then it is almost certainly a problem with your environment variable setup. To verify that, run printenv from your interactive shell to inspect your environment there. Then do the same thing inside the crontab (you will just need to temporarily set up an extra cron entry for it). Try setting the variables in your shell script before invoking Python.

On the other hand, if it doesn't work via batch(1) either, it could be something to do with the files that your code has open. Try running your shell script with input redirected from /dev/null and output going to a file:

$ /usr/local/bin/myscript </dev/null >|/tmp/outfile.txt 2>&1
James Youngman
  • 3,623
  • 2
  • 19
  • 21