Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python定义线程数_Python_Multithreading - Fatal编程技术网

Python定义线程数

Python定义线程数,python,multithreading,Python,Multithreading,我正在学习Python中的线程技术。我有一个基本的脚本正在运行,但在如何定义线程数方面遇到了问题。现在我有这样的事情: def my_fun(x): do something with open('filename', 'a') as f: f.write(results) for nodes in node_list: my_thread = threading.Thread(target=my_fun, args=(x,)) my_threa

我正在学习Python中的线程技术。我有一个基本的脚本正在运行,但在如何定义线程数方面遇到了问题。现在我有这样的事情:

def my_fun(x):
    do something
    with open('filename', 'a') as f:
        f.write(results)

for nodes in node_list:
    my_thread = threading.Thread(target=my_fun, args=(x,))
    my_thread.start()

这是可行的,但是node_列表中有179个节点,因此它创建了179个线程。我如何创建更少的线程,但仍然可以从列表中获取每个节点并在其上运行函数?该函数使用ssh登录到每个节点,运行show命令并将结果输出到文件。

Python版本2或3?Python版本3.5请查看以下内容: