Synchronize threads in python.