Python 实现异步调用函数

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u010649766/article/details/80692066

async_call.py

#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

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()
展开阅读全文

没有更多推荐了,返回首页