# 線程隔離 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 '''