python 使用装饰器开启多线程
参考资料:
python多线程详解(超详细) https://blog.csdn.net/weixin_40481076/article/details/101594705/
python实现多线程(简单操作) https://blog.csdn.net/weixin_44244190/article/details/124478884
Python使用装饰器开多线程 https://www.cnblogs.com/daiguoxi/p/15521405.html
👆这个方法我自己用的很多比较好用,可以将多线程的调用使用的很优雅整洁
python终止线程(直接return方便快捷doge) https://zhuanlan.zhihu.com/p/208260624
import time
import threading
def threadDecorator(func):
def wrapper(*args, **kwargs):
thread = threading.Thread(target=func, args=args, kwargs=kwargs)
thread.start()
return thread
return wrapper
@threadDecorator
def demoFunc():
for i in range(6):
print(i)
time.sleep(1)
@threadDecorator
def demoFunc02():
for i in range(6):
print(time.time())
time.sleep(1)
if __name__ == '__main__':
demoFunc()
demoFunc02()