码迷,mamicode.com
首页 > 编程语言 > 详细

localstack 线程隔离

时间:2019-09-03 09:59:39      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:线程   cal   imp   stack   targe   value   work   The   worker   

# 线程隔离
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 线程隔离

标签:线程   cal   imp   stack   targe   value   work   The   worker   

原文地址:https://www.cnblogs.com/gaofeng-d/p/11450829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!