Making it a MultiThread!

stas poritskiy stascrash at gmail.com
Fri Sep 20 12:11:34 EDT 2013


On Friday, September 20, 2013 7:56:16 AM UTC-5, stas poritskiy wrote:
> Hello All!
> 
> 
> 
> I have a general question, 
> 
> i was posting here earlier while trying to troubleshoot a few things while developing an application, i was able to hit all of my goals, and make things work! Thank you all who contributed to my research, and again, sorry for poor formatting of the threads, i am slowly learning;)
> 
> 
> 
> I am working on integration of multiple GUI (Tkinter) elements, such a progress bar, label update, etc, and throughout my research i discovered that i need to have Threading modules used to distribute the calls for GUI update and processing of my main App.
> 
> 
> 
> My Application is broken into multiple Classes(modules), and i wanted to hear your thought on the best practices to implement the Threading model.
> 
> 
> 
> I was thinking to create a new py-module, and reference all other modules/class to it, and create thread.start() objects, that would execute the GUI part, other will handle GUI Updates, and other - will be doing the processing.
> 
> 
> 
> Please share some of your thought on this approach, or maybe you may suggest a more effective way.
> 
> thanks !

Here is some CODE that i wrote to present the working case.
my main program is split in multiple modules, but this structure should represent what i am trying to get.

module name: multiProcessLauncher.py

import multiprocessing
import gui

def main():
    jobs = []
    p = multiprocessing.Process(target=gui.basicGui)
    jobs.append(p)
    p.start()
    
if __name__ == '__main__':
    main()
    pass


Module Name: gui.py

from Tkinter import *
import tkMessageBox
import Tkinter
import multiProcessLauncher
import action

def basicGui():
    g = action.Action()
    print "GUI"
    processor = multiProcessLauncher
    name = processor.multiprocessing.current_process().name
    print name, "starting"
    print name, "exiting"
  
    top = Tk()
    button = Button(top, text = "Press Me", command = g.do_something)
    button.pack()
    top.mainloop()

def main():
    pass
if __name__ == "__main__":
    main()

Module Name: action.py

class Action(object):
    def __init__(self):
        self.text = "Running Action"
    def do_something(self):
        print self.text

i am trying to figure out how to make use of multiprocessing access the PRINT from the action.py using the GUI button. if you run the code and press the button, the console will read nothing, but as soon as you close the GUI, it spits out the text to console. I read about using Que, but i am not sure how to implement, could someone suggest how? thank you



More information about the Python-list mailing list