我有一个接收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