Re: using filedescriptors in SIGINT signal handler



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



Relevant Pages

  • Re: Space Elevator by 2019?
    ... > to get the first thread in place. ... Give it to a cat. ... They can thread anything through anywhere first time, second time, third ...
    (sci.space.policy)
  • Re: Obnoxious little turd....
    ... >> Cats are something else, they can live in groups but each cat is ... I open the door, it is freezing outside. ... Sometimes I sit here at the computer and the door opens. ... It scared me the first time, ...
    (rec.pets.cats.anecdotes)
  • Re: My boss has me sussed (not OT)
    ... The first time my boss brings me a present back will indeed be the first and ... a breathing pretend cat would not be cheap. ... typing whizz kids who uses all their fingers- my boss Bev who is an ex- ...
    (rec.pets.cats.anecdotes)
  • Re: The game is up
    ... she can be a 'wild' cat again (a half persian pure white cat with a very ... needed to escape at the slightest touch of human danger, ... It took 5 years before I could close the door without him panicking about ... or bite, when I picked him up for the first time he just dangled saying "Oh, ...
    (rec.pets.cats.anecdotes)
  • Re: Diagnosis question
    ... I'm beginning to think that limbo is my middle name. ... twice andthe results weren't that good the first time, ... second time around. ... neuro that I see dx'd me with a combination of symptoms and a spinal tap. ...
    (alt.support.mult-sclerosis)

Loading