os.system() not returning

Yang fer7msb02 at sneakemail.com
Wed Nov 14 18:24:29 EST 2007


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 at soekris4801:~$ uname -a
Linux soekris4801 2.6.20-soekris #2 Sun Nov 4 19:07:00 EST 2007 i586 unknown
root at 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'



More information about the Python-list mailing list