Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54486

Re: Making it a MultiThread!

Newsgroups comp.lang.python
Date 2013-09-20 09:11 -0700
References <49c2ddff-9b80-4c0f-9272-2691f5f752d0@googlegroups.com>
Message-ID <19013711-d0c9-44a3-a8e2-b9d50eaea599@googlegroups.com> (permalink)
Subject Re: Making it a MultiThread!
From stas poritskiy <stascrash@gmail.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Making it a MultiThread! stas poritskiy <stascrash@gmail.com> - 2013-09-20 05:56 -0700
  Re: Making it a MultiThread! stas poritskiy <stascrash@gmail.com> - 2013-09-20 09:11 -0700
    Re: Making it a MultiThread! Piet van Oostrum <piet@vanoostrum.org> - 2013-09-21 21:00 -0400
      Re: Making it a MultiThread! Chris Angelico <rosuav@gmail.com> - 2013-09-22 11:18 +1000
      Re: Making it a MultiThread! stas poritskiy <stascrash@gmail.com> - 2013-09-23 07:14 -0700
        Re: Making it a MultiThread! Piet van Oostrum <piet@vanoostrum.org> - 2013-09-24 07:28 -0400

csiph-web