I have two threads in python (2.7). I start them at the beginning of my program. While they are running, my program reaches the end and exits, killing both of my threads before waiting for permission.
I am trying to figure out how to wait for both threads to complete before exiting.
def connect_cam(ip, execute_lock): try: conn = TelnetConnection.TelnetClient(ip) execute_lock.acquire() ExecuteUpdate(conn, ip) execute_lock.release() except ValueError: pass execute_lock = thread.allocate_lock() thread.start_new_thread(connect_cam, ( headset_ip, execute_lock ) ) thread.start_new_thread(connect_cam, ( handcam_ip, execute_lock ) )
In .NET, I would use something like WaitAll (), but I did not find the equivalent in python. In my script, TelnetClient is a long operation that can lead to a crash after a timeout.
python multithreading synchronization locking
Eric
source share