bug: threading, popen, os.kill and signals

Michael Ebert michael.m.ebert at daimlerchrysler.com
Thu Aug 8 04:47:11 EDT 2002


Hello,

   I encountered a strange bug in connection with popen and threading.
I want
to execute a shell command and kill it after a certain amount of time.
This
works, the shell command receives the SIGTERM signal:

----------------------------------------------
def inner(pid):
    try:
        os.kill(pid, signal.SIGTERM) # send a SIGTERM to the command
    except OSError, msg:
        pass

...
def do(command):
  child = popen2.Popen3(command, 1) # start the shell commmand
  time.sleep (0.1)                
    
  t = Timer(5, inner, [child.pid])  # kill command after 5 secs
  t.start()

do(command)                       
----------------------------------------------

BUT if the Timer thread, i.e. the "do" function, runs within a outer
thread, the shell command DOESN'T receive the SIGTERM signal:

CustomThread(do, args=(command,))

----------------------------------------------

Anybody any ideas? I'm working on HP UX 11.0.

michael



More information about the Python-list mailing list