![]() |
|
|
|
#1 |
|
Posts: n/a
|
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 |
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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> ================================================== ========================== |
|
|
|
#4 |
|
Posts: n/a
|
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> ================================================== ========================== |
|
|
|
#5 |
|
Posts: n/a
|
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 |
|
|
|
#6 |
|
Posts: n/a
|
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 -- |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| subprocess.Popen generates defunct | Mswed | Software | 1 | 07-29-2008 02:57 PM |