Strange python script behaviour

Å

Åukasz

Hi,
I have a problem with one of my python scripts. When I run this script
from command line it works correctly, but if I set up cron to run this
script on specified hour it works for a while and then "[Errno 32]
Broken pipe" error occures (always).

The strangest thing is that if I change command in CRON

from
python /home/xxx/script.py
to
python /home/xxx/script.py > /tmp/script.log 2>&1

the script always works correctly!!!

The question is WHY? Any ideas?
 
L

Loïc Domaigné

Hi,
I have a problem with one of my python scripts. When I run this script
from command line it works correctly, but if I set up cron to run this
script on specified hour it works for a while and then "[Errno 32]
Broken pipe" error occures (always).

The strangest thing is that if I change command in CRON

from
python /home/xxx/script.py
to
python /home/xxx/script.py  > /tmp/script.log 2>&1

the script always works correctly!!!

The question is WHY? Any ideas?

This is a cron issue, and has little with python to do.

By default, cron will email the output produced by your script, unless
you redirect. It does so by pipe to a "mail" program. Your error seems
to indicate a problem with the latter (perhaps you don't have any
"mail" program installed).

HTH,
Loïc
 
L

Lars Behrens

Åukasz said:
The strangest thing is that if I change command in CRON

from
python /home/xxx/script.py
to
python /home/xxx/script.py > /tmp/script.log 2>&1

the script always works correctly!!!

The question is WHY? Any ideas?

Seems to me that this is more of a shell thing...

First of all, it is always a good idea to call applications with their full
path from cronjobs:

/usr/bin/python /home/xxx/script.py or whatever the output of your "which
python" may be.

How did you create the cronjob? Dependending on the editor you used, maybe
there is a missing newline...
 
Å

Åukasz

Hi,
I have a problem with one of my python scripts. When I run this script
from command line it works correctly, but if I set up cron to run this
script on specified hour it works for a while and then "[Errno 32]
Broken pipe" error occures (always).
The strangest thing is that if I change command in CRON
from
python /home/xxx/script.py
to
python /home/xxx/script.py  > /tmp/script.log 2>&1
the script always works correctly!!!
The question is WHY? Any ideas?

This is a cron issue, and has little with python to do.

By default, cron will email the output produced by your script, unless
you redirect. It does so by pipe to a "mail" program. Your error seems
to indicate a problem with the latter (perhaps you don't have any
"mail" program installed).

Hmm... interesting, but logical explanation. Cron has its weird
issues. I guess I have to redirect outputs of all my scripts to /dev/
null in order to prevent them from this kind of error.

Thanks for help :)
 
Å

Åukasz

Seems to me that this is more of a shell thing...

First of all, it is always a good idea to call applications with their full
path from cronjobs:

/usr/bin/python /home/xxx/script.py or whatever the output of your "which
python" may be.

How did you create the cronjob? Dependending on the editor you used, maybe
there is a missing newline...

No, I've just simplified cron entries to not mess the example :) The
key thing was redirecting stdin & stderr to file. But thanks
anyway... :)
 
L

Loïc Domaigné

I have a problem with one of my python scripts. When I run this script
from command line it works correctly, but if I set up cron to run this
script on specified hour it works for a while and then "[Errno 32]
Broken pipe" error occures (always).
The strangest thing is that if I change command in CRON
from
python /home/xxx/script.py
to
python /home/xxx/script.py  > /tmp/script.log 2>&1
the script always works correctly!!!
The question is WHY? Any ideas?
This is a cron issue, and has little with python to do.
By default, cron will email the output produced by your script, unless
you redirect. It does so by pipe to a "mail" program. Your error seems
to indicate a problem with the latter (perhaps you don't have any
"mail" program installed).

Hmm... interesting, but logical explanation. Cron has its weird
issues. I guess I have to redirect outputs of all my scripts to /dev/
null in order to prevent them from this kind of error.

You could also set the MAILTO variable to "".


HTH,
Loïc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top