python 异步执行python脚本


async_call.py

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

在test.py中运用到了async_call.py文件中定义的async_call,运用到AA类中的hell0()函数中,使用装饰器@async_call


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM