子线程资源共享

子线程资源共享

from threading import Thread
import time ,os

x = 100
def task():
  global x
  x = 50
  print(os.getpid())#20456
  
if __name__ == '__main__':
  	t = Thread(target = task)
    t.start()
    time.sleep(2)
    print(x) # 50
    print(os.getpid()) #20456
原文地址:https://www.cnblogs.com/luodaoqi/p/11536907.html