标签:star port python reading read main 变量 结果 prope
import threading
import time
# 多线程执行同一任务时,局部变量是不共享的
def sum_num():
num = 0
i = 1
print("我进来了...")
time.sleep(1)
while i <= 20000000:
num += 1
i += 1
print("%s:%d" % (threading.Thread.name, num))
def main():
t1 = threading.Thread(target=sum_num)
t2 = threading.Thread(target=sum_num)
t1.start()
t2.start()
if __name__ == "__main__":
main()
我进来了...
我进来了...
<property object at 0x000002221D4F7E08>:20000000
<property object at 0x000002221D4F7E08>:20000000
标签:star port python reading read main 变量 结果 prope
原文地址:https://www.cnblogs.com/fry-hell/p/12826379.html