Python中多线程使用到Threading模块。Threading模块中用到的主要的类是Thread,我们先来写一个简单的多线程代码:
复制代码 代码如下:
author = 'Phtih0n'
import threading
class MyThread(threading.Thread):
def init(self):
threading.Thread.init(self)
def run(self):
global n
print n
n += 1
if "main" == name:
n = 0
ThreadList = []
for i in range(0, 10):
t = MyThread()
ThreadList.append(t)
for t in ThreadList:
t.start()
for t in ThreadList:
t.join
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8