Python程序教程

您现在的位置是:首页 >  Python

当前栏目

Python 实现异步调用函数

Python,实现,异步,调用函数
2025-04-07 09:01:30 时间

大家好,又见面了,我是你们的朋友全栈君。

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

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/157350.html原文链接:https://javaforall.cn