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