我有一个PyQT5小应用程序,它处理许多文件并加快我使用ProcessPoolExecutor的过程 .

处理这些文件的函数如下所示:

from concurrent.futures import ProcessPoolExecutor as PoolExecutor
def hide_elements(path_files):
    prog = ProgressBarWidget()
    proc_files = 0
    if file_path.exists() and file_path.is_dir():
        with PoolExecutor(max_workers=12) as e:
            max_files = len(list(file_path.glob('*.xml')))
            for file in file_path.glob('*.xml'):
                prog.update_prog_bar(proc_files, max_files, str(Path(file).name))
                e.submit(hide_elem(str(file)))
                proc_files += 1
                prog.update_prog_bar(proc_files, max_files, str(Path(file).name))
        e.shutdown(wait=False)

进度条是一个QWidget子项 .

主对话框的设计已经使用QtDesigner完成 . 该课程如下:

class dlgMain(QDialog, Ui_dlgMain):
"""
Class documentation goes here.
"""
    def __init__(self, parent=None):
        """
        Constructor

        @param parent reference to the parent widget
        @type QWidget
        """
        super(dlgMain, self).__init__(parent)
        self.setupUi(self)
        self.groupBox.setDisabled(True)
    def on_pbRun_clicked(self):
        ...
        hide_elements(file_path)

问题是,在编程时运行此函数会打开与运行许多进程一样多的窗口,而不是在后台运行这些进程 .

我已经部分解决了这个问题,将PoolExecutor更改为ThreadPoolExecutor而不是ProcessPoolExecutor,但我想了解它为什么会发生?