正在加载图片...
Python多线程编程 历忠荒子代枝大学 XIDIAN UNIVERSITY 口参考方法二:继承threading.Thread(0类,并重写run0( 推荐使用) #!/usr/bin/env python3 if name=='main': #-*-coding:utf-8 -* count 0 import threading,time threads =[ class myThread(threading.Thread): for i in range(5): def init (self,n): threads.append(myThread(1000)) threading.Thread._init(self) for t in threads: self.myThread_nn t.start() def run(self): time.sleep(5) global count print('count:',count) for i in range(self.myThread_n): count +1 #def ends Python多线程编程  参考方法二:继承 threading.Thread()类,并重写run()( 推荐使用) 5 #!/usr/bin/env python3 # -*- coding:utf-8 -*- import threading, time class myThread(threading.Thread): def __init__(self, n): threading.Thread.__init__(self) self.myThread_n = n def run(self): global count for i in range(self.myThread_n): count += 1 #def ends if __name__==’__main__’: count = 0 threads = [] for i in range(5): threads.append(myThread(1000)) for t in threads: t.start() time.sleep(5) print(‘count:’,count)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有