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

(七)8-3多线程共享变量

时间:2017-12-14 23:58:15      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:start   threading   +=   arp   def   imp   lis   read   线程   

 

多线程和多进程不同之处在于多线程本身就是可以和父进程共享内存的。

import threading
def worker(l):
l.append("cnblogs")
l.append("hello")
l.append("world")

if __name__ == "__main__":
l = list()
l += range(1, 10)
t = threading.Thread(target=worker,args=(l,))
t.start()
print(l)

  

运行结果
[1, 2, 3, 4, 5, 6, 7, 8, 9, ‘cnblogs‘, ‘hello‘, ‘world‘]

(七)8-3多线程共享变量

标签:start   threading   +=   arp   def   imp   lis   read   线程   

原文地址:http://www.cnblogs.com/pythonlx/p/8040500.html

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