By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

os.system() not returning

P: n/a
I have a Python program that does the following (pseudo-code):

while True:
is_downloading = True
use ftplib to download any new files from a server
is_downloading = False
os.system('make')
sleep(60)

To deal with intermittent connectivity/failures (this is running on a
mobile device), /etc/ppp/ip-up.local (a program that is run whenever
Internet connectivity is established) issues SIGUSR1 to the python
process, which handles it as such:

def handle_sigusr1(sig, bt):
global is_downloading, debug
if debug: print 'got SIGUSR1'; sys.stdout.flush()
if is_downloading:
args = ['python'] + sys.argv
if debug: print 'spawning', args; sys.stdout.flush()
pid = os.spawnvp(os.P_NOWAIT, 'python', args)
if debug: print 'pid', pid; sys.stdout.flush()
os.kill(os.getpid(), SIGTERM)
signal(SIGUSR1, handle_sigusr1)

(I start a new process since I didn't want to get into the business of
killing threads.)

However, os.system() occasionally does not return. It's just:

...
os.system('make -C ' + localpath + ' -f ' + makefiles[-1])
if debug: print 'sleeping'
...

and the stdout log always ends in "make: Leaving directory `/dldir'"
(make finishes). The python process is still running, but doesn't
respond to SIGUSR1, so perhaps it's still in the syscall. (SIGTERM
kills it, though; no SIGKILL needed.)

I separately tested that (a) python can be interrupted by SIGUSR1
while in blocking socket IO, and (b) SIGUSR1 doesn't screw up python
while in a os.system('make') (the signal gets handled after the call
returns).

Has anybody seen this kind of behavior, or might know what's going on?
Thanks in advance for any help.

FWIW, here is other info:

root@soekris4801:~$ uname -a
Linux soekris4801 2.6.20-soekris #2 Sun Nov 4 19:07:00 EST 2007 i586 unknown
root@soekris4801:~$ python -V
Python 2.5.1

Here are the commands the Makefile executes (repeatedly) - all
standard bash/command-line tools:

make: Entering directory `/dldir'
ls -1 /dldir/setup*.bash | tail -1 | xargs bash -x
+ set -o errexit
+ set -o nounset
+ mkdir -p /tftproot/
++ ls -1 /dldir/iii-03.tgz
++ sed 's/.*iii-\([0-9]*\)\.tgz.*/\1/'
++ tail -1
+ avail=03
++ cat /tftproot/iii-version
+ installed=03
+ '[' -z 03 ']'
+ (( installed < avail ))
make: Leaving directory `/dldir'
Nov 14 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.