[Tutor] "IOError: [Errno 32] Broken pipe" when running python with cron (alternatives?)

Emile van Sebille emile at fenx.com
Sun Mar 28 17:57:56 CEST 2010

On 3/27/2010 5:45 AM Karjer Jdfjdf said...
> I have made an extensive script that runs fine when started from the command line or IDLE.
> When I try to run it with cron it keeps giving errors:

Often when I have trouble running scripts from cron it's because 
something in the environment is different.

Try restructuring the way you start the script from cron.  Say your cron 
entry looks like:

* * * * * someone /usr/local/bin/myscript.py

Then something like:

env > /usr/local/bin/myscript.sh
echo /usr/local/bin/myscript.py >> /usr/local/bin/myscript.sh
chmod a+x /usr/local/bin/myscript.py

and change cron to

* * * * * someone /usr/local/bin/myscript.sh

and see if that helps.


> Error in sys.exitfunc:
> Traceback (most recent call last):
>    File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
>      func(*targs, **kargs)
>    File "/usr/lib/python2.6/logging/__init__.py", line 1508, in shutdown
>      h.flush()
>    File "/usr/lib/python2.6/logging/__init__.py", line 754, in flush
>      self.stream.flush()
> IOError: [Errno 32] Broken pipe
> The script has the following structure:
> 1. retrieves data from database 1
> 2. modifies the data
> 3. inserts the modified data in another database
> In a previous script I solved this problem with directing the stdout and stderr to /dev/null, but doing this isn't possible because I use pickle and write some data to files. It seems to have anything to do with the stdout/stderr and cron, but after a lot of googling I don't have any clues how to fix this.
> How can I solve this? Does anybody know how to solve this or is there a python-friendly alternative to cron that I can use.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list