我正在尝试使用tkinter和parallel.futures在gui中的多个文件上并发运行函数
在GUI之外,此脚本可以正常工作。但是,每当我将其转换为GUI脚本时,该脚本都会打开5个新的gui tkinter窗口(而不是并行运行该函数)(它打开的窗口数等于我允许程序使用的处理器数) 。
我已经彻底检查了代码,只是无法理解为什么它要打开新窗口,而不是仅对文件运行功能。
谁能看到我想念的东西吗?
下面是该代码的节略版本。我删去了大部分代码,只保留了与并行化相关的部分。毫无疑问,此代码中包含我在此示例中未定义的变量。]>
import pandas as pd
import numpy as np
import glob
from pathlib import Path
from tkinter import *
from tkinter import filedialog
from concurrent.futures import ProcessPoolExecutor
window = Tk()
window.title('Problem with parralelizing')
window.geometry('1000x700')
def calculate():
#establish where the files are coming from to operate on
folder_input = folder_entry_var.get()
#establish the number of processors to use
nbproc = int(np_var.get())
#loop over files to get a list of file to be worked on by concurrent.futures
files = []
for file in glob.glob(rf'{folder_input}'+'//*'):
files.append(file)
#this function gets passed to concurrent.futures. I have taken out a significant portion of
#function itself as I do not believe the problem resides in the function itself.
def process_file(filepath):
excel_input = excel_entry_var.get()
minxv = float(min_x_var.get())
maxxv = float(man_x_var.get())
output_dir = odir_var.get()
path = filepath
event_name = Path(path).stem
event['event_name'] = event_name
min_x = 292400
max_x = 477400
list_of_objects = list(event.object.unique())
missing_master_surface = []
for line in list_of_objects:
df = event.loc[event.object == line]
current_y = df.y.max()
y_cl = df.x.values.tolist()
full_ys = np.arange(min_x,max_x+200,200).tolist()
for i in full_ys:
missing_values = []
missing_v_y = []
exist_yn = []
event_name_list = []
if i in y_cl:
next
elif i not in y_cl:
missing_values.append(i)
missing_v_y.append(current_y)
exist_yn.append(0)
event_name_list.append(event_name)
# feed the function to processpool executer to run. At this point, I hear the processors
# spin up, but all it does is open 5 new tkinter windows (the number of windows is proportionate
#to the number of processors I give it to run
if __name__ == '__main__':
with ProcessPoolExecutor(max_workers=nbproc) as executor:
executor.map(process_file, files)
window.mainloop()
我正在尝试使用tkinter和current并发在gui中的多个文件上并发运行一个功能。在GUI之外,此脚本可以正常工作。但是,每当我将其翻译成...
我已经彻底检查了代码,只是无法理解为什么它要打开新窗口,而不是仅对文件运行功能。