We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 162d114 + 938f80d commit a963fbfCopy full SHA for a963fbf
1 file changed
recipes/Python/408859_socketrecv__three_ways_turn_it/recipe-408859.py
@@ -27,7 +27,11 @@ def recv_timeout(the_socket,timeout=2):
27
total_data.append(data)
28
begin=time.time()
29
else:
30
- time.sleep(0.1)
+ # Incase there is actually no data to be read from a non blocking socket,
31
+ # a socket.error exception is raised with EWOULDBLOCK OR EAGAIN
32
+ # If there is data of zero length read, it implies the socket was closed on the other end.
33
+ the_socket.close()
34
+ break
35
except:
36
pass
37
return ''.join(total_data)
0 commit comments