我有一個while True陳述句一遍又一遍地運行相同的功能,還有兩個計劃每 5 分鐘運行一次的功能。
但是,當作業被觸發運行時,回圈中的另一個函式已經在運行,作業被錯過了,我收到以下訊息:
Run time of job "SendHeroesToWork (trigger: interval[0:03:00], next run at: 2022-01-14 15:33:27 -03)" was missed by 0:00:03.169182
是否有任何方法可以強制計劃由 anyaway 運行的作業?甚至在到達適當的時間時停止當前功能并啟動計劃。
我的腳本來自main.py:
import asyncio
import tzlocal
from bot import ConnectWallet, LoginMetamask, TreasureHuntGame, NewMap, SkipErrorOnGame, RefreshHeroesPositions, SendHeroesToWork
from controllers import countdownTimer, setup_logger, initializePyAutoGUI, ReadConfigs, DeleteLogFiles
from apscheduler.schedulers.asyncio import AsyncIOScheduler
try:
streamConfig = ReadConfigs()
refresh_heroes_time = streamConfig['heroes_options']['refresh_heroes_time']
refresh_heroes_only = streamConfig['heroes_options']['refresh_heroes_only']
work_heroes_time = streamConfig['heroes_options']['work_heroes_time']
except FileNotFoundError:
print('Error: config.yaml file not found, make sure config.yaml are placed in the folder..')
exit()
async def main():
# Init message
print('\nPress Ctrl-C to quit at anytime!\n' )
# Initialize pyautogui library
await asyncio.create_task(initializePyAutoGUI())
# Countdown timer before start the bot
await asyncio.create_task(countdownTimer())
# Delete old log files
await asyncio.create_task(DeleteLogFiles())
# Create a scheduler for certain functions
scheduler = AsyncIOScheduler(timezone=str(tzlocal.get_localzone()))
if (refresh_heroes_time*60) > 9:
scheduler.add_job(RefreshHeroesPositions, 'interval', seconds=(refresh_heroes_time*60) 120, id='1')
if (work_heroes_time*60) > 0:
scheduler.add_job(SendHeroesToWork, 'interval', seconds=(work_heroes_time*60), id='2')
if len(scheduler.get_jobs()) > 0:
scheduler.start()
elif refresh_heroes_only != True:
while True:
# Steps of this bot:
# - Connect Wallet on BomberCypto game
await asyncio.create_task(ConnectWallet())
# - Login Metamask
await asyncio.create_task(LoginMetamask())
# - Treasure Hunt game mode
await asyncio.create_task(TreasureHuntGame())
# - New map feature
await asyncio.create_task(NewMap())
# - Check for errors on game
await asyncio.create_task(SkipErrorOnGame())
if __name__ == "__main__":
try:
loop = asyncio.get_event_loop()
loop.create_task(main())
loop.run_forever()
except Exception as e:
#logger = setup_logger()
#logger.error("Exception: " str(e))
print("Exception: " str(e))
exit()
uj5u.com熱心網友回復:
如果您需要強制停止當前正在運行的程式,請嘗試將其設定為突破位于實際回圈中的 if 陳述句?有點像故障保險,你最終可能需要添加它
uj5u.com熱心網友回復:
就我個人而言,我會添加一個 elif 陳述句來檢查該特定回圈的總運行時間,如果該值大于您希望它運行的量,則讓它運行中斷(結束回圈)
elif value > value
break
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/415007.html
標籤:
