Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

Python - subprocess.Popen

 
Thread Tools Search this Thread
Old 12-12-2004, 08:28 AM   #1
Michele Simionato
 
Posts: n/a
Default subprocess.Popen

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
  Reply With Quote
Old 12-12-2004, 01:01 PM   #2
Peter Hansen
 
Posts: n/a
Default Re: subprocess.Popen

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
  Reply With Quote
Old 12-12-2004, 11:03 PM   #3
Keith Dart
 
Posts: n/a
Default Re: subprocess.Popen

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>
================================================== ==========================
  Reply With Quote
Old 12-12-2004, 11:31 PM   #4
Keith Dart
 
Posts: n/a
Default Re: subprocess.Popen

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>
================================================== ==========================
  Reply With Quote
Old 12-13-2004, 12:07 AM   #5
Peter Hansen
 
Posts: n/a
Default Re: subprocess.Popen

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/Coo.../Recipe/347462

-Peter
  Reply With Quote
Old 12-13-2004, 04:21 PM   #6
P@draigBrady.com
 
Posts: n/a
Default Re: subprocess.Popen

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
--
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
subprocess.Popen generates defunct Mswed Software 1 07-29-2008 02:57 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47