使用Python怎么异步调用函数

使用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

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

关于使用Python怎么异步调用函数问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。