Python线程安全

try-finally 模式

import threading
lock = threading.Lock()
lock.acquire()
try:
   #do something
finally:
   lock.relase()

with 模式

import threading
lock = threading.Lock()
with lock:
   #do something
 
posted @ 2022-05-03 18:30  Asolitary  阅读(30)  评论(0编辑  收藏  举报