[英]Running a Function in the background while asking for more inputs
我正在使用 selenium 創建一個小數據處理腳本。 在我輸入我的值的地方,它運行一個函數來在網站上完成任務。 我想對輸入進行排隊,以便我可以在處理舊值時輸入新值。
while customername != 1:
print("Customer name")
customername = input()
print("Credit amount")
creditamount = input()
addcredit(driver, customername, creditamount)
當循環繼續並要求我提供下一組輸入時,如何讓函數 addcredit() 運行?
謝謝你們!
所以經過更多的研究,我使用了線程。
p1 = threading.Thread(target=addcredit, args=(driver, customername, creditamount))
p1.start()
這允許我的腳本按預期運行......它開始操作,然后允許我輸入更多數據以再次運行該操作。 根據我的理解,當第二個線程中調用的函數休眠時,它會彈回到第一個線程並繼續運行。 有人,如果我錯了,請糾正我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.