Using the socket module in python 2.7:
1. I received a socket object from a socket.accept() method.
2. I checked the timeout of the socket object and it returned -1.0. I think this means the socket object is in blocking mode.
3. However when I call the recv method on the socket object I receive the error:
[Errno 10035] A non-blocking socket operation could not be completed immediately
4. This error only makes sense if the socket object is non blocking. The socket object should block until data arrives.
Why is the socket object non blocking when it should be blocking?
NOTE: I have set a timeout on the socket which called the accept() method. Could this be causing the returned socket object to be non blocking as well? If so, I would grateful to hear an explanation as to why this is happening.
def wait_for_connection(self):
connection, client_address = self.sock.accept()
print 'connected to ' + str(client_address)
self.connections.append(connection)
def read_from_connections(self):
for connection in self.connections:
try:
command = connection.recv(1024)
if command:
print command
except socket.error, error:
print error
print connection._sock.timeout
if error.errno != errno.EWOULDBLOCK:
raise
What I have tried:
I've tried looking for blocking_mode property somewhere inside the socket object using the built in dir() method, but I was not successful. So I used the timeout property as an indicator of whether the socket is blocking or non blocking. Please let me know if this assumption is wrong.