python通过装饰器方式启动多线程

2022-11-02  本文已影响0人  Time一柒

代码

from time import sleep
from threading import Thread

def async_thread(function):
    def wrapper(*args, **kwargs):
        thr = Thread(target=function, args=args, kwargs=kwargs)
        thr.start()
    return wrapper

@async_thread
def A(a):
    sleep(a)
    print("3秒钟。。。。。。")
    print("a 结束")

def B():
    print("b 结束")


A(3)
B()
上一篇下一篇

猜你喜欢

热点阅读