我运行的脚本需要运行许多外部命令。我有几个命令块需要一起并行运行。你知道吗
因此,我需要控制这个线程池是否已完成,以启动下一个线程池。你知道吗
要运行的命令:
import pathlib
def thread_command(path_files, command):
_path_files= pathlib.Path(path_files)
if pathlib.Path(path_files).exists():
for file in _path_files.glob('**/*.ext'):
ext_file = Ext(file, path_files, tmp_rules)
if threads == None:
threads.insert(0, threading.Thread(target=command))
else:
threads.append(threading.Thread(target=command))
return threads
#Threads running
command1 = ext_file.command1
command2= ext_file.command2
threads1 = thread_command(pathToFiles, command1)
for thread in threads:
thread.daemon = True
thread.start()
do_other_things()
threads2 = thread_command(pathToFiles, command2)
for thread in threads2:
thread.daemon = True
thread.start()
我需要找到一种方法或一个过程来控制线程的第一个列表何时完成,以继续执行程序。 总之,我想运行整个列表线程,并等待所有在那里运行的线程完成,然后启动第二个线程池。你知道吗
提前谢谢你的帮助。你知道吗
不要使用“daemon”线程,而是等待它们连接回主线程,例如:
但是你的
thread_command()
函数本身并没有什么意义——对于初学者来说,当你试图插入/附加threads
列表时,你会得到一个错误,因为它没有被定义(至少不在函数上下文中)。第二,为什么要一遍又一遍地检查每个命令的文件列表,除非您希望文件列表发生更改?你知道吗相关问题 更多 >
编程相关推荐