Python 线程启动的四种方式

import threading,_thread
def action(i):
    print(i **32)
#带有状态的子类
class Mythread(threading.Thread):
    def  __init__(self, i):
        self.i = i
        threading.Thread.__init__(self)
    def run(self):
        print(self.i ** 32)
Mythread(2).start()

#传入行为
thread = threading.Thread(target=(lambda: action(2))
thread.start()

#不封装lambda
thread.Thread(target=action, args=(2,)).start()

#基本的线程模块
_thread.start_new_thread(action,(2,))

转载于:https://www.cnblogs.com/ArvinZhao/p/9166631.html

你可能感兴趣的:(Python 线程启动的四种方式)