popen3,4 and SIGTERM

Discussion in 'Python' started by Zoran Bosnjak, Oct 15, 2003.

  1. 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'
     
    Zoran Bosnjak, Oct 15, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Teresa
    Replies:
    2
    Views:
    659
    Rob Thorpe
    Apr 6, 2004
  2. Jane Austine
    Replies:
    2
    Views:
    1,184
    Donn Cave
    Aug 16, 2003
  3. Andrew Athan
    Replies:
    0
    Views:
    425
    Andrew Athan
    Jan 6, 2004
  4. Andrew Athan
    Replies:
    0
    Views:
    478
    Andrew Athan
    Jan 6, 2004
  5. Andreas Otto
    Replies:
    2
    Views:
    234
    Andreas Otto
    Oct 12, 2010
Loading...

Share This Page