python线程间数据共享(示例演示)

```
import threading

data_list = []

def task(arg):
data_list.append(arg)
print(data_list)

def run():
for i in range(10):
p = threading.Thread(target=task, args=(i,))
p.start()

if name == 'main':
run()

'''
[0]
[0, 1]
[0, 1, 2]
[0, 1, 2, 3]
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, 4, 5, 6]
[0, 1, 2, 3, 4, 5, 6, 7]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
'''

猜你喜欢

转载自www.cnblogs.com/apollo1616/p/10351461.html