Question

I am looking for an optimum sleep value to receive data from a non-blocking socket. E.g:

while True:
    data=s.recv(1024)
    if not data:
        time.sleep(10) #10ms
    else:
        pass #...

No sleep would lead into 100% CPU usage, so any idea how to get the best CPU Usage and bandwith? How long has a sleep to be so the CPU can do a thread switch?

Btw, does it make sense to set the buffer of the socket via SO_SNDBUF/SO_RECVBUF and set TCP_NODELAY or shouldn't they be combined?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top