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,))
posted @ 2018-06-11 13:34  大头大头灬下雨不愁  阅读(1984)  评论(0编辑  收藏  举报