Python中多线程及程序锁浅析

411次阅读  |  发布于5年以前

Python中多线程使用到Threading模块。Threading模块中用到的主要的类是Thread,我们先来写一个简单的多线程代码:

复制代码 代码如下:

coding : uft-8

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