popen3,4 and SIGTERM

Z

Zoran Bosnjak

This simple script works with python2.1.1, but it does not work with any
newer version of python on linux. Do you think it is a bug? Where?

This program does nothing, it just suppose to end after 3 seconds,
but os.kill(...) does not kill the ping process. Even if I do it from
the shell, I need to use kill -9 <pid>.

With python2.1.1 it works as expected.

regards,
Zoran

---- cut here
import os, time, signal, threading, string
from popen2 import Popen3, Popen4

pid = 0

def run():
global pid
f = Popen4('ping localhost')
pid = f.pid
print 'pid from thread', pid
while 1:
s = f.fromchild.readline()
if not s: break


t = threading.Thread(target=run)
t.start()
time.sleep(3)
print 'timeout'
print 'pid from main', pid
os.kill(pid, signal.SIGTERM)
t.join()
print 'bye'
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top