当前位置: 首页 > 工具软件 > LocalStack > 使用案例 >

localstack 线程隔离

松阳泽
2023-12-01
# 线程隔离
from werkzeug.local import LocalStack
import threading

# 首先实例化
my_stack = LocalStack()
my_stack.push(1)  # 主线程入栈


def worker():
    print("in worker thread the value is:", my_stack.top)
    my_stack.push(2)  # 在worker thread里面push一个元素
    print("in worker thread,after push element,the value is:", my_stack.top)


t = threading.Thread(target=worker, name="worker thread")
t.start()  # 开启线程
print("finally,in the main thread,the value is:", my_stack.top)
'''
in worker thread the value is: None
finally,in the main thread,the value is: 1
in worker thread,after push element,the value is: 2
'''

转载于:https://www.cnblogs.com/gaofeng-d/p/11450829.html

 类似资料: