Re: using filedescriptors in SIGINT signal handler
- From: jepler@xxxxxxxxxxxxxx
- Date: Tue, 13 Sep 2005 08:02:57 -0500
If you're talking about a Python function registered as a handler by
signal.signal, then there should not be any restrictions on what you do
in that function.
Here's a small program I wrote:
#------------------------------------------------------------------------
import os, signal, time
def h(*args): os.write(fd, "data\n");
print "my pid is", os.getpid()
subproc = os.popen("cat -n", "w")
fd = subproc.fileno()
signal.signal(signal.SIGINT, h)
while 1:
time.sleep(1)
#------------------------------------------------------------------------
I ran this and in another terminal I repeatedly typed 'kill -INT nnnn',
where nnnn is the pid printed by my program. Each time, another line is
output by 'cat'.
When I try to deliver the signal by hitting ctrl-c in that terminal, the
first time nothing happens and the second time I get the message
OSError: [Errno 32] Broken pipe
in this case, I believe that the first signal was delivered to cat,
causing it to exit. The second signal was delivered to the python
program, which obviously couldn't write to the stdin of a process that
had exited.
Jeff
Attachment:pgpKc8qh82PWm.pgp
Description: PGP signature
- References:
- using filedescriptors in SIGINT signal handler
- From: Bram Stolk
- using filedescriptors in SIGINT signal handler
- Prev by Date: Re: Checked tree in wxpython (windows)
- Next by Date: round() wrong in Python 2.4?
- Previous by thread: using filedescriptors in SIGINT signal handler
- Next by thread: round() wrong in Python 2.4?
- Index(es):
Relevant Pages
|
Loading