waste of resources ?

Hrvoje Niksic hniksic at srce.hr
Mon Jun 7 22:38:08 CEST 1999


Bryan VanDeVen <bryanv at arlut.utexas.edu> writes:

> On sysV or Unix98 systems you may set the disposition of SIGCHLD to
> SIG_IGN (i.e., ignore death or a child signals) The watertight
> method is to catch SIGCHLD and have the handler call waitpid(...) 
> with WNOHANG in a loop.

Except that when a signal arrives during an IO operation, it will be
canceled due to the EINTR brain-damage, and Python will throw an
exception.  So if you expect your program to accept SIGCHLD signals at
random intervals, you'd better encase all your IO operation in a loop
like this:

while 1:
    try:
        read(...)             # or whatever
    except (IOError, os.error), detail:
        if detail.args[0] == errno.EINTR:
            continue
        else:
            raise

This problem with signals has been my long-standing gripe with Python.




More information about the Python-list mailing list