参考:https://blog.csdn.net/jasonliujintao/article/details/77531519
#coding:utf-8
from time import sleep
from threading import Thread
def async(f):
def wrapper(*args, **kwargs):
thr = Thread(target=f, args=args, kwargs=kwargs)
thr.start()
return wrapper
class A():
def __init__(self):
self.num=1
@async
def A(self):
sleep(5)
self.num=8
print("a function {}".format(self.num))
def B(self):
self.num=3
for i in range(10):
sleep(1)
print("b function {}".format(self.num))
if __name__ == '__main__':
a=A()
a.A()
a.B()