Python Forum
Multiprocessing in wx Frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing in wx Frame
#2
I make some changes and test it. It looks like multiprocessing not able to run inside wx Frame. My purpose is after clicking the button, function_1 will be started in a separate process and the control will turn back to wx Frame MainLoop so I can continue to do other things like making changes in the grid, don't need to wait 2 minutes. is it possible? Thanks.

import time
import wx.grid
from multiprocessing import Process

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Multiprocessing", size=(600, 500), pos = (300, 300))
        wx.Panel(self)
        self.SetBackgroundColour("Blue")
        grid = wx.grid.Grid(self, size=(400,100), pos=(100,100))
        grid.CreateGrid(3,3)
        for c in range(3): grid.SetColSize(c,100)
        for r in range(3):
            grid.SetRowLabelValue(r,time.strftime('%H:%M:%S'))
            for c in range(3):  grid.SetCellValue(r, c, "R"+str(r)+"/C"+str(c))
        runButton = wx.Button(self, label="Run it", pos=(250, 250))
        runButton.Bind(wx.EVT_BUTTON, self.onClick)
    def onClick(self,event):
##        p = Process(target=self.function_1)
##        p.start()
        self.function_1()
        print('function_1 run 2 minutes and return result.')
    def function_1(self):
        time.sleep(120)
if __name__ == "__main__":
    app = wx.App()
    win = Frame()
    win.CreateStatusBar()
    win.Show()
    app.MainLoop()
Reply


Messages In This Thread
Multiprocessing in wx Frame - by ian - Aug-16-2017, 08:41 PM
RE: Multiprocessing in wx Frame - by ian - Aug-19-2017, 12:53 AM
RE: Multiprocessing in wx Frame - by snippsat - Aug-19-2017, 08:49 AM
RE: Multiprocessing in wx Frame - by ian - Aug-20-2017, 08:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 9,130 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 11,286 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 6,553 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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