当前位置:   article > 正文

Python 实现异步调用函数_async_call

async_call

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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/102600
推荐阅读
相关标签
  

闽ICP备14008679号