在apscheduler中執行fabric的定時任務時:
正常的寫法是這樣的
scheduler.add_job(updataPicture.gettime, 'cron', day_of_week='0-6', hour=18, minute=15)
可是在時間到達的時候執行結果是這樣的:
No hosts found. Please specify (single) host string for connection:
結果會讓我從新輸入主機名api
通過查詢在Stack Overflow上找了答案:ide
In order to get hosts to work in a script outside of the fab command-line tool and fabfile.py, you'll have to use execute(): from fabric.tasks import execute def mytask(): run('uname -a') results = execute(mytask)
這樣的話主機就能夠工做在腳本之外了,我在原有fabric文件中執行code
def getlatestpics(): execute(updatapic)
而後定時任務這樣:ip
scheduler.add_job(updataPicture.getlatestpics, 'cron', day_of_week='0-6', hour=18, minute=15)
這樣就能夠很是完美的執行了ci