1. 程式人生 > >python 多執行緒處理IO操作

python 多執行緒處理IO操作

from threading import Thread

方法1

t = Thread(target=func, args=(1,))
t.start()

方法2

clasee MyThread(Thread):
    def __init__(self, sid):
    self.sid = sid
    Thread.__init__(self)

    def run(self):
        handle(self.sid)

threads = []
for i in range(1, 11):
    t = MyThead(1)
    threads.append(t)
    t.start()


for
t in threads: t.join() # 阻塞函式