Python 实现异步调用函数的示例讲解

Python 实现异步调用函数的示例讲解,第1张

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 实现异步调用函数的示例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/3285963.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-05
下一篇 2022-10-05

发表评论

登录后才能评论

评论列表(0条)

保存