localstack 线程隔离
Posted gaofeng-d
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了localstack 线程隔离相关的知识,希望对你有一定的参考价值。
# 线程隔离
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
'''
以上是关于localstack 线程隔离的主要内容,如果未能解决你的问题,请参考以下文章
werkzeug(flask)中的local,localstack,localproxy探究
python- flask current_app详解,与 current_app._get_current_object()的区别以及异步发送邮件实例