Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu?
#1
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.")

Quote
#2
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)
Quote
#3
the gnome-shell take up 100% percent of cpu
Quote
#4
up..........
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Tkinter scaling windows conten to or with its size not working Detzi 5 157 Jan-12-2020, 12:42 PM
Last Post: Detzi
  How to close one of the windows in Tkinter scratchmyhead 3 266 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Using tkinter on Windows to launch python 3 scripts Mocap 1 260 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  Int Variables in different Tkinter windows only returning 0 harry76 3 615 May-26-2019, 10:24 AM
Last Post: Yoriz
  [Tkinter] Ignore windows scaling in tkinter Gangwick 2 1,135 Jul-23-2018, 02:41 PM
Last Post: Gangwick
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 3,961 Mar-27-2018, 11:44 AM
Last Post: nortski
  Multi windows in tkinter buttons not responding correctly curtjohn86 13 4,277 Jul-01-2017, 03:42 PM
Last Post: nilamo
  [Tkinter] Tkinter GUI works on Windows but not on Ubuntu danbei 8 4,252 Jun-27-2017, 08:03 PM
Last Post: danbei

Forum Jump:


Users browsing this thread: 1 Guest(s)