Python Forum
[Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu?
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.")
Reply
#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)
Reply
#3
the gnome-shell take up 100% percent of cpu
Reply
#4
up..........
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter two windows instead of one jacksfrustration 7 774 Feb-08-2024, 06:18 PM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,135 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Tkinter multiple windows in the same window tomro91 1 784 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Dual Tkinter windows and shells Astrikor 6 3,832 Sep-03-2020, 10:09 PM
Last Post: Astrikor
  Tkinter scaling windows conten to or with its size not working Detzi 5 4,354 Jan-12-2020, 12:42 PM
Last Post: Detzi
  How to close one of the windows in Tkinter scratchmyhead 3 4,758 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Using tkinter on Windows to launch python 3 scripts Mocap 1 2,685 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  Int Variables in different Tkinter windows only returning 0 harry76 3 4,082 May-26-2019, 10:24 AM
Last Post: Yoriz
  [Tkinter] Ignore windows scaling in tkinter Gangwick 2 4,418 Jul-23-2018, 02:41 PM
Last Post: Gangwick
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 10,872 Mar-27-2018, 11:44 AM
Last Post: nortski

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020