import thread lk = thread.allocate_lock() def foo(): lk.acquire() # Acquire the lock critical section lk.release() # Release the lock