Discussion:
sending ctrl C to a process
(too old to reply)
s***@yahoo.com
2006-03-29 02:14:51 UTC
Permalink
hi
i have a program that works very similar to tail -f in Unix
It will need a Ctrl-C in order to break out of the program.
I wish to run this program using python (either thru os.system() or
some other subprocess modules) and how can i pass Ctrl-C to this
program to terminate it in python?
thanks
Felipe Almeida Lessa
2006-03-29 02:21:07 UTC
Permalink
Post by s***@yahoo.com
It will need a Ctrl-C in order to break out of the program.
I wish to run this program using python (either thru os.system() or
some other subprocess modules) and how can i pass Ctrl-C to this
program to terminate it in python?
$ python2.4 && echo " **** Python terminates!"
Python 2.4.2 (#2, Mar 27 2006, 21:07:39)
[GCC 4.0.3 (Debian 4.0.3-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Post by s***@yahoo.com
^C
KeyboardInterrupt
... while 1:
... pass
... except KeyboardInterrupt:
... print "\nHey, why did you press Ctrl-C?!"
... except:
... print "\nStrange..."
...
^C
Hey, why did you press Ctrl-C?!
Post by s***@yahoo.com
import sys
... while 1:
... pass
... except KeyboardInterrupt:
... sys.exit(0)
...
^C
**** Python terminates!
$

HTH,
--
Felipe.
s***@yahoo.com
2006-03-29 03:36:53 UTC
Permalink
hi
thanks for the reply.Actually, i should clarify what i am doing.
the program's output will be displayed to a web browser using cgi, so
there is no
keyboard interrupt. The backend cgi script (python script) will have to
send Ctrl-C to break the program.
thanks
Grant Edwards
2006-03-29 04:12:59 UTC
Permalink
Post by s***@yahoo.com
hi
thanks for the reply.
Please properly quote the article to which you're replying so
that we can tell who/what your talking to/about.
Post by s***@yahoo.com
Actually, i should clarify what i am doing. the program's
output will be displayed to a web browser using cgi, so there
is no keyboard interrupt. The backend cgi script (python
script) will have to send Ctrl-C to break the program.
Actually, you don't want to send a Ctrl-C to the program. You
want to send a SIGINT signal to the process. That's what the
tty line-discipline layer in the tty driver sends to processes
attached to a tty when the tty receives the interrupt character
(which defaults to Ctrl-C).

Sending signals to processes is done using os.kill()

http://docs.python.org/lib/os-process.html
--
Grant Edwards grante Yow! How do I get HOME?
at
visi.com
Continue reading on narkive:
Loading...