subprocess.Popen

Discussion in 'Python' started by Michele Simionato, Dec 12, 2004.

  1. I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I
    wonder why a "kill" method is missing. I am just adding it via subclassing,

    class Popen(subprocess.Popen):
    def kill(self, signal = SIGTERM):
    os.kill(self.pid, signal)

    but I would prefer to have it in the standard Popen class. I am surprised
    it is not there. Any comments?

    Michele Simionato
     
    Michele Simionato, Dec 12, 2004
    #1
    1. Advertising

  2. Michele Simionato

    Peter Hansen Guest

    Michele Simionato wrote:
    > I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I
    > wonder why a "kill" method is missing. I am just adding it via subclassing,
    >
    > class Popen(subprocess.Popen):
    > def kill(self, signal = SIGTERM):
    > os.kill(self.pid, signal)
    >
    > but I would prefer to have it in the standard Popen class. I am surprised
    > it is not there. Any comments?


    Likely this is at least part of the answer:

    c:\>python
    Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on
    win32
    >>> import os
    >>> os.kill

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    AttributeError: 'module' object has no attribute 'kill'


    Note the "on win32" part above...

    -Peter
     
    Peter Hansen, Dec 12, 2004
    #2
    1. Advertising

  3. Michele Simionato

    Keith Dart Guest

    Michele Simionato wrote:
    > I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I
    > wonder why a "kill" method is missing. I am just adding it via subclassing,
    >
    > class Popen(subprocess.Popen):
    > def kill(self, signal = SIGTERM):
    > os.kill(self.pid, signal)
    >
    > but I would prefer to have it in the standard Popen class. I am surprised
    > it is not there. Any comments?


    Probably because it is not entirely portable. If you want a more
    complete, but Posix-only (at least Linux and FreeBSD), process
    management and spawning then you can use the proctools module in pyNMS.

    http://sourceforge.net/projects/pynms/





    --
    \/ \/
    (O O)
    -- --------------------oOOo~(_)~oOOo----------------------------------------
    Keith Dart <>
    vcard: <http://www.kdart.com/~kdart/kdart.vcf>
    public key: ID: F3D288E4 URL: <http://www.kdart.com/~kdart/public.key>
    ============================================================================
     
    Keith Dart, Dec 13, 2004
    #3
  4. Michele Simionato

    Keith Dart Guest

    Keith Dart wrote:
    > Michele Simionato wrote:
    >
    >> I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I
    >> wonder why a "kill" method is missing. I am just adding it via
    >> subclassing,
    >>
    >> class Popen(subprocess.Popen):
    >> def kill(self, signal = SIGTERM):
    >> os.kill(self.pid, signal)
    >>
    >> but I would prefer to have it in the standard Popen class. I am surprised
    >> it is not there. Any comments?

    >
    >
    > Probably because it is not entirely portable. If you want a more
    > complete, but Posix-only (at least Linux and FreeBSD), process
    > management and spawning then you can use the proctools module in pyNMS.
    >
    > http://sourceforge.net/projects/pynms/
    >


    I forgot to mention that the pyNMS package also has a module called
    "expect" that works like the Expect language. You can interact and
    control interactive processes and external CLIs with it.




    --
    \/ \/
    (O O)
    -- --------------------oOOo~(_)~oOOo----------------------------------------
    Keith Dart <>
    vcard: <http://www.kdart.com/~kdart/kdart.vcf>
    public key: ID: F3D288E4 URL: <http://www.kdart.com/~kdart/public.key>
    ============================================================================
     
    Keith Dart, Dec 13, 2004
    #4
  5. Michele Simionato

    Peter Hansen Guest

    Peter Hansen wrote:
    > Michele Simionato wrote:
    >> I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I
    >> wonder why a "kill" method is missing. I am just adding it via
    >> subclassing,


    > [Peter, noting os.kill is absent in win32]


    Note, for the record, however, Jimmy Retzlaff's excellent recipe
    for Win32 process termination, which can work with ctypes or
    pywin32, and with either the PID such as popen returns and
    subprocess.Popen stores, or the "handle" that spawn returns
    (and which subprocess.Popen stores in its _handle attribute):

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347462

    -Peter
     
    Peter Hansen, Dec 13, 2004
    #5
  6. Michele Simionato

    Guest

    Michele Simionato wrote:
    > I was looking at Python 2.4 subprocess.Popen. Quite nice and handy, but I
    > wonder why a "kill" method is missing. I am just adding it via subclassing,
    >
    > class Popen(subprocess.Popen):
    > def kill(self, signal = SIGTERM):
    > os.kill(self.pid, signal)
    >
    > but I would prefer to have it in the standard Popen class. I am surprised
    > it is not there. Any comments?


    Seems like an ommission, but probably due
    to windows implementation problems?

    Note my subprocess.py that was referenced
    in pep 324 does have a kill method:
    http://www.pixelbeat.org/libs/subProcess.py
    Note also that it also kills any children
    of the subProcess using process groups.

    --
    Pádraig Brady - http://www.pixelbeat.org
    --
     
    , Dec 13, 2004
    #6
    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. Ivo Woltring
    Replies:
    4
    Views:
    3,559
    Jeff Shannon
    Jan 27, 2005
  2. John Abel
    Replies:
    2
    Views:
    3,307
    John Abel
    May 12, 2005
  3. Earl Eiland
    Replies:
    3
    Views:
    529
    Peter Hansen
    May 16, 2005
  4. Trent Mick
    Replies:
    0
    Views:
    481
    Trent Mick
    May 16, 2005
  5. File.popen/IO.popen

    , May 20, 2006, in forum: Ruby
    Replies:
    1
    Views:
    233
    Robert Klemme
    May 20, 2006
Loading...

Share This Page