1
所以我有一個任務需要執行一定的時間,每天發生三次。Python,每天做任務3次而其他的事情正在發生?
我已經建立了這個代碼使用了一個名爲附表
包,做https://pypi.python.org/pypi/schedule
我喜歡,這是我可以說,在每一天,或者類似的東西凌晨3:00運行。
然而,問題是,我想我的其他代碼在同一時間運行,而不是停留在相同的循環調度是在
運行,因此,現在它看起來是這樣的:
def archerPull():
#insert code for calling archer pull here
with open("LogsForStuffPull.txt", "a") as myfile:
myfile.write("time: " + time.ctime(time.time()))
#this is code for scheduling job to do every day
def schedulingTasks(firstTime, secondTime, thirdTime, fourthTime, fivthTime):
schedule.every().day.at(firstTime).do(archerPull)
schedule.every().day.at(secondTime).do(archerPull)
schedule.every().day.at(thirdTime).do(archerPull)
schedule.every().day.at(fourthTime).do(archerPull)
schedule.every().day.at(fivthTime).do(archerPull)
schedulingTasks("13:46", "13:47", "13:48", "13:49", "13:50")
while True:
schedule.run_pending()
time.sleep(1)
正如你所看到的,循環將永遠是真的,因此每天運行調度器。但是如果我想將其他東西與它融合在一起,它會永遠循環嗎?
我要的任務是indivitual發生的歷史(是異步的話吧)
請幫我,謝謝!
你可以運行良好看看python的[multiprocessing](https://docs.python.org/3/library/multiprocessing.html)或[threading](https://docs.python.org/3/library/threading.html)來安排你的任務。 –
嘿@ kiran.koduru,將BackgroundScheduler(通過apScheduler)是一個好主意嗎? – user3196126
我從來沒有使用它,但你可以嘗試使用它。它確實支持異步調用。 –