[IPython-dev] Subtle ls bug :(

Evan Patterson epatters at enthought.com
Fri Aug 27 10:07:09 EDT 2010


A summer or two ago I was writing some socket code and ran into
precisely this problem. When a Unix process receives a signal and is
the middle of a call that can potentially block forever (reading from
a pipe in our case), it will interrupt the kernel-level system call
involved. The solution usually employed is to simply restart the call
if it is interrupted. I think the following should be sufficient:

import errno

def read_no_interrupt(f):
    while True:
        return f.read()
    except IOError, err:
        if err.errno != errno.EINTR:
            raise

Evan

On Fri, Aug 27, 2010 at 12:18 AM, Brian Granger <ellisonbg at gmail.com> wrote:
>
> Can you both try the following:
>
> Just keep typing ls return.  Every so often I get:
>
> In [28]: ls
> ---------------------------------------------------------------------------
> IOError                                   Traceback (most recent call last)
> /Library/Frameworks/Python.framework/Versions/6.2/Doc/<ipython
> console> in <module>()
>
> /Users/bgranger/Documents/Computation/IPython/code/ipython/IPython/zmq/zmqshell.pyc
> in system(self, cmd)
>     61         sys.stderr.flush()
>     62         p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
> ---> 63         for line in p.stdout.read().split('\n'):
>     64             if len(line) > 0:
>     65                 print line
>
> IOError: [Errno 4] Interrupted system call
>
> This only seems to show up when running the qt GUI mode.  I think this
> one will be fun to debug :)
>
> Brian
>
> --
> Brian E. Granger, Ph.D.
> Assistant Professor of Physics
> Cal Poly State University, San Luis Obispo
> bgranger at calpoly.edu
> ellisonbg at gmail.com



More information about the IPython-dev mailing list