1. 程式人生 > >用類的方法實現thread

用類的方法實現thread

import threading
import time

class Mythread(threading.Thread):
    def __init__(self,n):
        super(Mythread,self).__init__()
        self.n=n

    def run(self):
            print("task",self.n)
            time.sleep(2)


t1=Mythread("t1")

t2=Mythread("t2")


t1.run()
t2.run()