from threading import Condition
from threading import Thread
from threading import current_thread
flag = False
cond_var = Condition()
def child_task():
global flag
name = current_thread().getName()
cond_var.acquire()
if not flag:
cond_var.wait()
print("\n{0} woken up \n".format(name))
flag = False
cond_var.release()
print("\n{0} exiting\n".format(name))
thread1 = Thread(target=child_task, name=“thread1”)
thread2 = Thread(target=child_task, name=“thread2”)
thread1.start()
thread2.start()
cond_var.acquire()
cond_var.notify_all()
cond_var.release()
thread1.join()
thread2.join()
print(“main thread exits”)