Socket read weirdness

Ulrich Berning berning at teuto.de
Thu May 3 02:35:41 EDT 2001


Casey Crabb wrote:

> Ok, I have discovered a strange issue with sockets:
> Here's the situation:
>  I am in X, or windows, and have a term open running a command-line
> python program
>  I have a thread which is reading from the socket.
>  If I resize the terminal the read from the socket is broken:
>  I am returned a socket.error, (4, 'Interrupted system call'),
> <traceback object at 0x82deb88>
>  The also occurs if I restart my window manager (FVWM2)
> My question is: What does resizing the window running a command-line
> python application have to do with reading from a socket?
>
> Any insight would be most appreciated,
>
> Casey

You should expect, that a blocking system call like recv() can
always be interrupetd by the operating system. I use the following
code to detect an interruped system call and restart it.

----------------------------------------
def socket_read(sock_fd, data_size):
    remain = data_size
    data = ''
    while remain > 0 :
        try:
            new_data = sock_fd.recv(remain)
        except socket.error, args:
            if args[0] == errno.EINTR:
                continue
            else:
                raise
        else:
            count = len(new_data)
            if not count:
                return None
        data = data + new_data
        remain = remain - count
    return data
----------------------------------------

Ulli

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20010503/767938c3/attachment.html>


More information about the Python-list mailing list