1. 程式人生 > >Python簡單的多線程demo:裝逼寫法

Python簡單的多線程demo:裝逼寫法

__init__ () 面向 thread sta init run pre pan

用面向對象來寫多線程:

import threading

class MyThread(threading.Thread):
    def __init__(self, n):
        super(MyThread, self).__init__()
        self.n = n
    def run(self):
        print("running task:",self.n)


t1 = MyThread("t1")
t2 = MyThread("t2")
t1.start()
t2.start()

Python簡單的多線程demo:裝逼寫法