signals and system calls

Michael Stenner mstenner at phy.duke.edu
Wed Apr 9 13:09:42 EDT 2003


So, searching the archives, I see that this issue has been touched on
several times over the last 8 or so years.  I'm wondering if anyone
has a solution to my little problem:

I have a long-running python program.  I want it to terminate nicely
(ie not lose data) upon certain common signals.  The problem comes
with system calls.  If a system call is interruped by a signal, it
ends up raising an exception.  Now, the way you address this in C is
to set SA_RESTART via sigaction, but that doesn't appear the be
available in python.  [ I trust there is a good reason, btw, and am
curious about it, but am trying to keep this email goal-oriented :) ]

I've seen it suggested that you simply catch the exception and redo
the system call, but that gets REALLY ugly.  To do it reliably, you
need to wrap ALL system calls, including all the writes, reads, sends,
recvs, selects, etc. in ALL OF THE MODULES YOU USE.

Just to be clear, I'm not trying to "use" signals here.  They exist,
they WILL be sent (when a system shuts down, for example), and I'm
just trying to tolerate them in a way that doesn't lose data.

So, the bottom line is:  what do people recommend?  

				Thanks,
				 Michael
-- 
  Michael Stenner                       Office Phone: 919-660-2513
  Duke University, Dept. of Physics       mstenner at phy.duke.edu
  Box 90305, Durham N.C. 27708-0305





More information about the Python-list mailing list