1. 程式人生 > >多執行緒相關

多執行緒相關

import time
from threading import Thread
def func(n):
    #time.sleep(1)
    print(n)
for i in range(10):
    t = Thread(target=func,args=(i,))
    t.start()
 
 
import time
from threading import Thread
class MyThread(Thread):
    def __init__(self,args):
        super().__init__()
        self.args 
= args def run(self): time.sleep(1) print(self.args) for i in range(10): t = MyThread(i) t.start()