即使目標函式正在接收這兩個引數,它仍然會因缺少引數而引發錯誤?想知道為什么
check_device() missing 1 required positional argument: 'device_id'
Job "check_device (trigger: interval[0:00:30], next run at: 2021-11-05 19:35:24 IST)" raised an exception
調度程式截圖
def job_add(application_id,device_id,count):
scheduler.add_job(
check_device,
'interval',
args = (application_id,device_id,),
seconds=7,
jobstore = 'default',
id=f'my_job_{count}',
replace_existing=True,
max_instances = 7,
misfire_grace_time=None
)
我正在呼叫的函式
def check_device(application_id,device_id):
print('Mqtt connected ... calling on ',application_id,device_id)
mqttc = mqtt.Client(clientId)
uj5u.com熱心網友回復:
這是您的代碼的虛擬版本。確保傳遞引數并正確呼叫函式:
from apscheduler.schedulers.blocking import BlockingScheduler
def check_device(application_id, device_id):
print(f"Application id: {application_id}, Device id: {device_id}")
scheduler = BlockingScheduler()
def job_add(application_id, device_id, count):
scheduler.add_job(
check_device,
"interval",
args=(
application_id,
device_id,
),
seconds=2,
jobstore="default",
id=f"my_job_{count}",
replace_existing=True,
max_instances=7,
misfire_grace_time=None,
)
job_add(application_id=5, device_id=2, count=1)
scheduler.start()
uj5u.com熱心網友回復:
好的,所以發布此答案以供將來參考,我相信 APS 以某種方式將每個作業(函式)簽名存盤在資料庫中我之前添加了一個帶有一個引數的作業,在進行更改后,它也在搜索先前定義的函式,但它有沒有device_id 的位置引數,解決方案,只需從資料庫中洗掉以前的作業歷史(這個答案可能不準確,但如果它似乎無緣無故地給出上述錯誤,洗掉相關的作業歷史應該完成這項作業)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/349991.html
下一篇:django錯誤:NoReverseMatchat/watchlist/Reversefor'viewList'witharguments'('',)
