User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 402,050 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,464 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 295 | Replies: 3
Reply
Join Date: Jun 2008
Posts: 6
Reputation: splakhin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
splakhin splakhin is offline Offline
Newbie Poster

Multi threads ... ???

  #1  
Jul 17th, 2008
Hi everybody!
I wrote for my company one little test application: Frame , Pmw.NoteBook and few buttons.
and one main button 'Start' under NoteBook which starts process depend on name of Pmw.NoteBook...
everything is fine , the problem is each of the processes run ~10 min and all this time: button 'Start' is still pressed; GUI not responsable at all, so I can't go to another Tab and start another process...
I guess it multithreading issue ... Does somebody has little example to start two processes from one button?
Will be very appreciated for any suggestion.
Thanks,
Slava.
Last edited by splakhin : Jul 17th, 2008 at 5:01 pm.
Attached Images
File Type: jpg myForm.JPG (20.2 KB, 7 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: India
Posts: 271
Reputation: Agni is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 36
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Whiz in Training

Re: Multi threads ... ???

  #2  
Jul 18th, 2008
yes you need to make it multi-threaded. Everytime the user clicks on the button it can spawn a new thread which does the work and the button is free for input. i think this code should help you

  1. from Tkinter import *
  2. import threading
  3. import time
  4.  
  5. class process(threading.Thread):
  6. def __init__(self):
  7. threading.Thread.__init__(self)
  8.  
  9. def run(self):
  10. print 'hello'
  11. time.sleep(60)
  12. print 'bye'
  13.  
  14. #The class process derives from threading.Thread. whenver we say process.start it spawns #a new thread and calls it's 'run' method
  15. def startThread():
  16. process().start()
  17.  
  18. root = Tk()
  19. frame = Frame(root)
  20. frame.pack()
  21.  
  22. #when user clicks button it calls 'startThread' command
  23. but = Button(frame,text='start',command=startThread)
  24. but.pack()
  25.  
  26. text = Text(frame)
  27. text.pack()
  28.  
  29. root.mainloop()

you'll see that each thread sleeps for a minute but the input button doesn't wait for the output and is ready to take the next input. Once each thread finishes it prints the 'bye' message.

I'm fairly new to multi-threading myself so if you find any issues with this let me know or any doubts.
thanks
-chandra
Reply With Quote  
Join Date: Jun 2008
Posts: 6
Reputation: splakhin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
splakhin splakhin is offline Offline
Newbie Poster

Re: Multi threads ... ???

  #3  
Jul 22nd, 2008
Thanks. Agni, sorry was out...
hm make sense .... so how I understand class "process" should communicate with procedure invoked from my "Start" button? This is the question for me: should class "process" contain my whole program or how ?
Thanks!
Reply With Quote  
Join Date: Jun 2008
Posts: 6
Reputation: splakhin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
splakhin splakhin is offline Offline
Newbie Poster

Re: Multi threads ... ???

  #4  
Jul 28th, 2008
Does anybody else can suggest me how to tight my Start button with "class process(threading.Thread):" ?

Thanks in advance!
Slava
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 11:48 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC