Python 实现异步调用函数的示例讲解
更新时间:2018年10月14日 16:46:05 作者:独一无二的小个性
今天小编就为大家分享一篇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 实现异步调用函数的示例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Python中内置函数append()、extend()的用法及区别详解
这篇文章主要介绍了Python中内置函数append()、extend()的用法及区别,还探讨了append()函数添加列表时发生的同步变化问题,并提供了解决方案,需要的朋友可以参考下2025-03-03


最新评论