[ python-Bugs-976613 ] socket timeout problems on Solaris

SourceForge.net noreply at sourceforge.net
Mon Jun 21 08:20:40 EDT 2004


Bugs item #976613, was opened at 2004-06-21 11:36
Message generated for change (Comment added) made by astrand
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=976613&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Peter Åstrand (astrand)
Assigned to: Nobody/Anonymous (nobody)
>Summary: socket timeout problems on Solaris

Initial Comment:
The timeout stuff in the socket module does not work
correctly on Solaris. Here's a typical example:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("localhost", 9048))
s.listen(1)
s.settimeout(10)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()

When connecting, I get this traceback:

Connected by ('127.0.0.1', 32866)
Traceback (most recent call last):
  File "foo.py", line 10, in ?
    data = conn.recv(1024)
socket.error: (11, 'Resource temporarily unavailable')

This is because Python treats the new socket object as
blocking (the timeout value is -1). However, in
Solaris, sockets returned from accept() inherits the
blocking property. So, because the listenting socket
was in non-blocking mode, the new connected socket will
be non-blocking as well. Since the timeout is -1,
internal_select will not call select. 

The solution to this problem is to explicitly set the
blocking mode on new socket objects. The attached patch
implements this. 


----------------------------------------------------------------------

>Comment By: Peter Åstrand (astrand)
Date: 2004-06-21 14:20

Message:
Logged In: YES 
user_id=344921

One workaround for this problem is:

socket.setdefaulttimeout(somethinglarge)

Or, if you have the possibility, you can do
conn.setblocking(1) right after accept(). 

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=976613&group_id=5470



More information about the Python-bugs-list mailing list