Python 实现异步调用函数

2020-01-08 16:30:53 浏览数 (1)

async_call.py

代码语言:javascript复制
#coding:utf-8
from threading import Thread

def async_call(fn):
    def wrapper(*args, **kwargs):
        Thread(target=fn, args=args, kwargs=kwargs).start()

    return wrapper

test.py

代码语言:javascript复制
from time import sleep
from async_call import async_call

class AA:
    @async_call
    def hello( self ):
        self.__count  = 1
        print(int(time.()))
        sleep(2)
        print(int(time.()))
        return

if __name__ == "__main__":

    AA().hello()

0 人点赞