waste of resources ?

Diego Dainese ddainese34x at x22dsi.unive.it
Fri Jun 11 13:30:01 CEST 1999

On Tue, 8 Jun 1999 01:03:03 +0300, Moshe Zadka wrote:
> On 7 Jun 1999, Hrvoje Niksic wrote:
> <about syscalls throwing EINTR and aborting>
> > I don't know about Perl, but a good fix would be to have the
> > interpreter do the hard work for us.  If a system call fails and errno 
> > is EINTR, then the signal handler should be called, *and* the syscall
> > should be restarted.

I'm agree with this also.

> Ummmmm......
> You can do the hard-work yourself, but once and for all:

Yes, but this is boring ;)

> def myread(file):
> 	while 1:
> 		try:
> 			return file.read()
> 		except (IOError, os.error), detail:
> 			if detail.args[0] != errno.EINTR: raise
> And just call myread(foo) instead of  foo.read(). 
> Where's the catch-22?

IMHO a better approach is a function like this:

  def temp_failure_retry(func, *args):
      while 1:
              return apply(func, args)
          except (IOError, os.error), detail:
              if detail.args[0] != errno.EINTR: raise  

(the strange function name come from the similar C macro used in the
GNU libc ;)

An example of the use of this function with open:

    fd = temp_failure_retry(open, "pippo", "w");

I don't tryed it, but AFAIK it should work.


d i e g o
To reply remove the numbers and the `x' from my address
Sorry for my bad English!

More information about the Python-list mailing list