subprocess kill

L

luca72

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )

then i kill:
self.luca.Kill()

but the process is still active and the file self.f_s_l increase it
size because the process is not killed.

How i can kill the process?
Regards

Luca
 
M

Mike Driscoll

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )

then i kill:
self.luca.Kill()

but the process is still active and the file self.f_s_l increase it
size because the process is not killed.

How i can kill the process?
Regards

Luca

See http://lmgtfy.com/?q=python+kill+subprocess+linux

When I do that on my machine, the 2nd result has the answer:

http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kill-a-subprocess
 
L

luca72

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )
then i kill:
self.luca.Kill()
but the process is still active and the file self.f_s_l increase it
size because the process is not killed.
How i can kill the process?
Regards

Seehttp://lmgtfy.com/?q=python+kill+subprocess+linux

When I do that on my machine, the 2nd result has the answer:

http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kil...

Hello Mike i have also test but they never kill the process the file
(stdout=self.f_s_l) increase it's size, haveyou some idea.
also if i close the program the process is still active.

Regards

Luca
 
L

luca72

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )
then i kill:
self.luca.Kill()
but the process is still active and the file self.f_s_l increase it
size because the process is not killed.
How i can kill the process?
Regards
Luca
Seehttp://lmgtfy.com/?q=python+kill+subprocess+linux

When I do that on my machine, the 2nd result has the answer:

Hello Mike i have also test but they never kill the process the file
(stdout=self.f_s_l) increase it's size, haveyou some idea.
also if i close the program the process is still active.

Regards

Luca

i'm able only to kill via shell like kill -9 process pid, Why?
 
L

luca72

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )
then i kill:
self.luca.Kill()
but the process is still active and the file self.f_s_l increase it
size because the process is not killed.
How i can kill the process?
Regards
Luca
Seehttp://lmgtfy.com/?q=python+kill+subprocess+linux
When I do that on my machine, the 2nd result has the answer:
http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kil....
Hello Mike i have also test but they never kill the process the file
(stdout=self.f_s_l) increase it's size, haveyou some idea.
also if i close the program the process is still active.

Luca

i'm able only to kill via shell like kill -9 process pid, Why?

Now the only way to solve the problem is to call a c program that kill
the process via subprocess in other case i can't close it, i have also
try with

subprocess.Popen(['kill -9 dvbtune'] shell=True), but the process is
still active

Regards

Luca
 
C

Carl Banks

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )
then i kill:
self.luca.Kill()
but the process is still active and the file self.f_s_l increase it
size because the process is not killed.
How i can kill the process?
Regards
Luca
Seehttp://lmgtfy.com/?q=python+kill+subprocess+linux
When I do that on my machine, the 2nd result has the answer:
http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kil...
-------------------
Mike Driscoll
Blog:  http://blog.pythonlibrary.org
Hello Mike i have also test but they never kill the process the file
(stdout=self.f_s_l) increase it's size, haveyou some idea.
also if i close the program the process is still active.
Regards
Luca
i'm able only to kill via shell like kill -9 process pid, Why?

Now the only way to solve the problem is to call a c program that kill
the process via subprocess in other case i can't close it, i have also
try with

subprocess.Popen(['kill -9 dvbtune'] shell=True), but the process is
still active

This is not working because the kill command does not accept the name
of a program. You have to give it a process id.

As for your general question, we really can't answer it. There a lot
of reasons a process might not die when you try to kill it: it could
be trapping and ignoring signals (which is rude but it happens), it
could be stuck in a critical section, the program might be threaded
and not handling signals well, the program might have forked itself
and the original process id has disappeared, etc. We can't read your
mind or divine what's running on your computer, so we can't answer
your question. We can only suggest things that might be wrong. It's
up to you to investigate and/or dig deeper.


Carl Banks
 
L

luca72

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )
then i kill:
self.luca.Kill()
but the process is still active and the file self.f_s_l increase it
size because the process is not killed.
How i can kill the process?
Regards
Luca
Seehttp://lmgtfy.com/?q=python+kill+subprocess+linux
When I do that on my machine, the 2nd result has the answer:
http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kil...
-------------------
Mike Driscoll
Blog:  http://blog.pythonlibrary.org
Hello Mike i have also test but they never kill the process the file
(stdout=self.f_s_l) increase it's size, haveyou some idea.
also if i close the program the process is still active.
Regards
Luca
i'm able only to kill via shell like kill -9 process pid, Why?
Now the only way to solve the problem is to call a c program that kill
the process via subprocess in other case i can't close it, i have also
try with
subprocess.Popen(['kill -9 dvbtune'] shell=True), but the process is
still active

This is not working because the kill command does not accept the name
of a program.  You have to give it a process id.

As for your general question, we really can't answer it.  There a lot
of reasons a process might not die when you try to kill it: it could
be trapping and ignoring signals (which is rude but it happens), it
could be stuck in a critical section, the program might be threaded
and not handling signals well, the program might have forked itself
and the original process id has disappeared, etc.  We can't read your
mind or divine what's running on your computer, so we can't answer
your question.  We can only suggest things that might be wrong.  It's
up to you to investigate and/or dig deeper.

Carl Banks

The firs thing that i have tested is with the process id get by
Popen.pid ,but it don't works.
Thanks
 
Y

Yinon Ehrlich

Hello i'm using subprocess in this way:
self.luca = subprocess.Popen(['/usr/bin/
dvbtune'+frase_sint],shell=True, stdout=self.f_s_l,stderr=self.f_s_e )
then i kill:
self.luca.Kill()
but the process is still active and the file self.f_s_l increase it
size because the process is not killed.
How i can kill the process?
Regards
Luca
Seehttp://lmgtfy.com/?q=python+kill+subprocess+linux
When I do that on my machine, the 2nd result has the answer:
http://stackoverflow.com/questions/1064335/in-python-2-5-how-do-i-kil...
-------------------
Mike Driscoll
Blog:  http://blog.pythonlibrary.org
Hello Mike i have also test but they never kill the process the file
(stdout=self.f_s_l) increase it's size, haveyou some idea.
also if i close the program the process is still active.
Regards
Luca
i'm able only to kill via shell like kill -9 process pid, Why?
Now the only way to solve the problem is to call a c program that kill
the process via subprocess in other case i can't close it, i have also
try with
subprocess.Popen(['kill -9 dvbtune'] shell=True), but the process is
still active
This is not working because the kill command does not accept the name
of a program.  You have to give it a process id.
As for your general question, we really can't answer it.  There a lot
of reasons a process might not die when you try to kill it: it could
be trapping and ignoring signals (which is rude but it happens), it
could be stuck in a critical section, the program might be threaded
and not handling signals well, the program might have forked itself
and the original process id has disappeared, etc.  We can't read your
mind or divine what's running on your computer, so we can't answer
your question.  We can only suggest things that might be wrong.  It's
up to you to investigate and/or dig deeper.
Carl Banks

The firs thing that i have tested is with the process id get by
Popen.pid ,but it don't works.
Thanks

I guess you run python > 2.6 (Popen.kill is new in Python 2.6)

You may try terminate (http://docs.python.org/library/
subprocess.html#subprocess.Popen.terminate)
or the following wrapper - good for older pythons too as well as
killing group of processes:
http://benjamin.smedbergs.us/blog/2006-12-11/killableprocesspy/

-- Yinon
 
N

Nobody

When using shell=True, your process is started in a shell, meaning the
PID of your subprocess is not self.luca.pid, self.luca.pid is the PID of
the shell.

This isn't true for a simple command on Unix (meaning a program name plus
arguments, and redirections, rather than e.g. a pipeline or a command
using subshells, flow-control constructs, etc).

For a simple command, "/bin/sh -c 'prog arg arg ...'" will exec() the
program *without* fork()ing, so the program will "take over" the shell's
process and PID.

You can verify this by running e.g.:

import subprocess
p = subprocess.Popen('sleep 10', shell=True)
print p.pid
subprocess.call('ps')
p.wait()
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top