You can use settimeout() , as in this example:
import socket tcpServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcpServer.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcpServer.bind(('0.0.0.0', 10000))
The loop will run until stopped is set to true and then exits after (at most) the timeout you set. (In my application, I pass the connection descriptor to the newly created thread and continue the loop to be able to accept additional concurrent connections.)
fuenfundachtzig
source share