[Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? (/thread-18638.html) |
Using tkinter and mutiprocess ok on windows, locks up on ubuntu? - ice - May-25-2019 the code run well in windows but it is leading to interface stuck(the whole system interface) under the ubuntu(16.04 and 18.04). what's wrong? thank you! run.py # #!/usr/bin/python3 # #-*-coding: UTF-8 -*- import tkinter from tkinter import filedialog as tkFiledialog import plotMagDynamic def plotMagDynamicLine(): plotMagDynamic.plotUsingMultiprocessing() if __name__ == '__main__': # plotMagDynamicLine() top=tkinter.Tk(className='plot') frm = tkinter.Frame(top) tkinter.Button(frm, text="plot",command =plotMagDynamicLine,width=20,height=2).pack(side=tkinter.LEFT) text=tkinter.Text(top,width=60,height=20) frm.pack(side=tkinter.TOP) top.mainloop()plotMagDynamic.py # #!/usr/bin/python3 # #-*-coding: UTF-8 -*- import tkinter from tkinter import filedialog as tkFiledialog import os import pandas as pd import numpy as np import matplotlib.pyplot as plt import configparser import re import math import yaml#读取配置文件 import multiprocessing from multiprocessing import Pool as ProcessPool#多进程 def plotProcessing(name): t=[1,2,3] TM=[1,2,3] RE=[1,2,3] fig = plt.figure(num=1, figsize=(15, 8)) # 开启一个窗口,同时设置大小,分辨率 ax1 = fig.add_subplot(1,1,1) # 通过fig添加子图,参数:行数,列数,第几个。 ax1.plot(t, TM, label='TM') ax1.plot(t, RE, label='RE') ax1.hlines(0, 0, np.max(t), colors="r", linestyles="dashed") ax1.set_xlabel("Time [ps]") ax1.set_ylabel("Normalized Magnetization (m_z)") ax1.legend() # 显示图例 pngPath = "./plot_" + str(name) + ".png" if (os.path.exists(pngPath) == True): os.remove(pngPath) fig.savefig(pngPath) plt.close('all') print(pngPath) #多进程 def multi_wrapper(args): return plotProcessing(*args) def plotUsingMultiprocessing(): nameArr=[9,8,7] cpu_count=multiprocessing.cpu_count()#返回本计算机的cpu数量(包括超线程,一般是指核心,而非物理cpu个数) pool=0 if(cpu_count-2>0): pool = ProcessPool(processes = cpu_count-2) else: pool = ProcessPool(processes = 1) zip_args = list(zip(nameArr))#由于不给传入多个参数,现目前使用折中方法解决 results = pool.map(multi_wrapper, zip_args) pool.close() pool.join() print ("Sub-process(es) done.") RE: Using tkinter and mutiprocess ok on windows, locks up on ubuntu? - ice - May-25-2019 it is run well in the virtual machine(ubuntu 18.04) but it is leading to interface stuck in my host(ubuntu 18.04) and my friend's host system(ubuntu 16.04) RE: Using tkinter and mutiprocess ok on windows, locks up on ubuntu? - ice - May-25-2019 the gnome-shell take up 100% percent of cpu RE: Using tkinter and mutiprocess ok on windows, locks up on ubuntu? - ice - May-29-2019 up.......... |