Does Event and Lock do the same thing in these scenes?
class MyThread1(threading.Thread):
def __init__(event):
self.event = event
def run(self):
self.event.wait()
# do something
self.event.clear()
another:
class MyThread2(threading.Thread):
def __init__(lock):
self.lock = lock
def run(self):
self.lock.acquire()
# do something
self.lock.release()
If you wait on an event, the execution stalls until an
event.set()happensAcquiring a lock only stalls if the lock is already acquired
Both classes have different use cases. This article will help you understand the differences.