我有一個接收2個參數的函數。該功能實際上連接了某些通信設備,並在其CLI中寫入了多條線路。如何使用4對不同的參數同時運行相同的函數?
我需要在4個設備上同時執行相同的CLI寫操作。
通過使用下面的代碼(只有一個例子不引用func1的內容)我知道如何運行一個執行此功能的線程。但是,我不知道如何啓動4個線程。
import _thread
def func1(arg1, arg2):
print("Write to CLI")
_thread.start_new_thread(func1, (DUT1_CLI, '0'))
您可以在線程,例如下一行的新調用,只是寫: '_thread.start_new_thread(FUNC1,(DUT1_CLI, '0')) _thread.start_new_thread(FUNC1,(DUT2_CLI, '0')) ' 該差異將是 –
在python中,如果任何名稱以下劃線開頭,則應避免使用它(在這種情況下,請導入該模塊)。看看這個問題的更多細節:https://stackoverflow.com/questions/1301346/what-is-the-meaning-of-a-single-and-a-double-underscore-before-an-object-名稱 – GPhilo
考慮更改'_thread' for ['threading'](https://docs.python.org/2/library/threading.html) – GPhilo