Python 实现异步调用函数

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

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()

猜你喜欢

转载自blog.csdn.net/ieeso/article/details/82347136
今日推荐