import eventlet eventlet.monkey_patch() import time import socket import threading done = False CV = threading.Condition() def thread(): global CV CV.acquire() try: while not done: CV.wait(30) finally: CV.release() eventlet.spawn(thread) def thread2(): s = socket.socket() s.bind(('localhost', 1111)) s.listen(10) s.accept() s.close() eventlet.spawn(thread2) time.sleep(50) CV.acquire() try: done = True CV.notify() finally: CV.release()