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,))


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM