471,317 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

os.system() not returning

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

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

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
0 1007

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Juan Galdeano | last post: by
23 posts views Thread by pauldepstein | last post: by
1 post views Thread by nido | last post: by
reply views Thread by =?Utf-8?B?QW50b25pbyBPJydOZWFs?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.