Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > subprocess.Popen

Reply
Thread Tools

subprocess.Popen

 
 
Michele Simionato
Guest
Posts: n/a
 
      12-12-2004
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
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      12-12-2004
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
 
 
 
 
Keith Dart
Guest
Posts: n/a
 
      12-13-2004
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 <(E-Mail Removed)>
vcard: <http://www.kdart.com/~kdart/kdart.vcf>
public key: ID: F3D288E4 URL: <http://www.kdart.com/~kdart/public.key>
================================================== ==========================
 
Reply With Quote
 
Keith Dart
Guest
Posts: n/a
 
      12-13-2004
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 <(E-Mail Removed)>
vcard: <http://www.kdart.com/~kdart/kdart.vcf>
public key: ID: F3D288E4 URL: <http://www.kdart.com/~kdart/public.key>
================================================== ==========================
 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      12-13-2004
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
 
P@draigBrady.com
Guest
Posts: n/a
 
      12-13-2004
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

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

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




Advertisments