正在加载图片...
Python多线程编程 历安毛子代枚大 XIDIAN UNIVERSITY 口参考方法一:将要执行的函数作为参数传递给 threading.Thread() #!/usr/bin/env python3 for i in range(5): #-*-coding:utf-8-*- threads.append(threading.Thread(target import threading,time =func,args=(1000,))) def func(n): for t in threads: global count t.start() time.sleep(0.1) time.sleep(5) for i in range(n): print('count:',count) count +1 #main ends #def ends if name=='main': count =0 threads [ Python多线程编程  参考方法一:将要执行的函数作为参数传递给 threading.Thread() 3 #!/usr/bin/env python3 # -*- coding:utf-8 -*- import threading, time def func(n): global count time.sleep(0.1) for i in range(n): count += 1 #def ends if __name__==’__main__’: count = 0 threads = [] for i in range(5): threads.append(threading.Thread(target =func, args=(1000,))) for t in threads: t.start() time.sleep(5) print(‘count:’,count) #main ends
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有