The Thread-safe new_lock Function in Python
July 4, 2023•48 words
# Async lock
def new\_lock():
event = aio.Event()
return event.wait(),event.set
# Async lock thread-safe
def new\_lock\_ts():
class Event\_Ts(aio.Event):
def set(self):
self.\_loop.call\_soon\_threadsafe(super().set)
event = Event\_Ts()
return event.wait(),event.set