Python 多线程 类和方法

import threading
import time
import random

def threadFun():
    for i in range(10):
        print("ThreadFun - %d" %i)
        time.sleep(random.randrange(0,2))

class ThreadClass(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        for i in range(10):
            print("ThreadClass - %d" %i)
            time.sleep(random.randrange(0,2))

if __name__ == "__main__":
    tFunc = threading.Thread(target = threadFun)
    tCls = ThreadClass()
    tFunc.start()
    tCls.start()
    tFunc.join()
    tCls.join()

 

posted on 2016-05-26 16:14  漫步的影子  阅读(672)  评论(0编辑  收藏  举报