Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > signals (again)

Reply
Thread Tools

signals (again)

 
 
bill
Guest
Posts: n/a
 
      08-10-2005
I see this (or similar) question occasionally looking back through the
archive, but haven't yet seen a definitive answer, so I'm going to ask
it again.

Consider the following:

while True:
do_something_to_files_in_directory(fd)
fcntl(fd, F_NOTFIY, DN_CREATE)
signal.pause()


How do you deal with the signal that occurs after the fcntl and before
the pause? The solution to sleep instead of pause is aesthetically
ugly and doesn't really help. I've thought about examining the stack
trace in the signal handler for SIGIO and responding appropriately, but
that's pretty ugly too. I saw some mention of implementing a try:
construct that would delay receipt of the signal for one atomic python
instruction, and that seemed like a good idea, but I didn't see much
follow up on that. What's the pythonic thing to do here? How can I
guarantee timely response to the creation of a file in the directory
referenced by fd?

 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      08-11-2005
"bill" <(E-Mail Removed)> writes:
> What's the pythonic thing to do here? How can I
> guarantee timely response to the creation of a file in the directory
> referenced by fd?


Use asynchronous calls and/or a separate thread.
 
Reply With Quote
 
 
 
 
bill
Guest
Posts: n/a
 
      08-11-2005
How does that help? I interpret "use asynchronous calls" to mean "use
fcntl to set an FN_NOTIFY on the directory in order to be alerted when
something needs to be done." But the method of doing that which I
outlined above has a critical section in which the incoming signal will
not be noticed. All of the solutions I can think of for getting around
it involve a lot of acrobatics that I'm fairly certain aren't
necessary, and more to the point I don't think they actually solve the
problem. There is always a section in which the signal arrives just
before the pause, so it doesn't wake us up out of the pause as it is
intended to. We can set globals in the signal handler, and then check
them right before the pause, but if they get set after we check, then
we're hosed. I was hoping that perhaps the following code might be
atomic:

if notify_occurred or signal.pause():

but I'm almost certain that it's not.

The problem is localized, so I don't see how invoking a seperate thread
is useful. Could you elaborate on how you think that will help?

 
Reply With Quote
 
Michael Hudson
Guest
Posts: n/a
 
      08-11-2005
"bill" <(E-Mail Removed)> writes:

> I see this (or similar) question occasionally looking back through the
> archive, but haven't yet seen a definitive answer, so I'm going to ask
> it again.
>
> Consider the following:
>
> while True:
> do_something_to_files_in_directory(fd)
> fcntl(fd, F_NOTFIY, DN_CREATE)
> signal.pause()
>
>
> How do you deal with the signal that occurs after the fcntl and before
> the pause?


I don't think you can, sorry.

Cheers,
mwh

--
Get out your salt shakers folks, this one's going to take more
than one grain. -- Ator in an Ars Technica news item
 
Reply With Quote
 
bill
Guest
Posts: n/a
 
      08-12-2005
I found a good solution to this problem in Richard Steven's
_Network_Programming_. It seems like everything shows up in Steven's
books! Rather than pausing, you do a blocking read on a pipe. You
only write to the pipe from within the signal handler. However, this
brings up the better question: why was 'pause' ever implemented? No
matter what you do, the signal that you expect to wake you up may occur
immediately prior to the pause, and you'll miss it. Starting that
question in a new thread.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dumping real signals in VCD Sajan VHDL 8 07-21-2007 07:39 AM
Are all the signals read in the process should appear in the sensitivity list of the process? walala VHDL 3 09-09-2003 07:47 AM
generate testbench for array signals Simone Winkler VHDL 1 09-02-2003 04:00 PM
Delay of control signals Ingmar Seifert VHDL 0 08-18-2003 03:21 PM
unused bits in signals Thomas VHDL 2 07-06-2003 10:22 PM



Advertisments