It does not block. It's just that your main thread does nothing after the first sock.recv(1024) . You must tell him to constantly collect data:
MAIN THREAD
threading.Thread(target=Thread2, args=(sock,)).start() while True: data = sock.recv(1024) if not data: break print data
Please note that you cannot easily interrupt this process. To do this, you need to set the thread as a daemon:
MAIN THREAD
t = threading.Thread(target=Thread2, args=(sock,)) t.daemon = True t.start() while True: data = sock.recv(1024) if not data: break print data
Also, when you go through args , don't forget to pass the tuple, i.e. args=(sock,) instead of args=(sock) . For Python, args=(sock) equivalent to args=sock . This is probably a criminal!
I do not see any more problems in your code.
source share