Threads? help

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2008
Posts: 13
Reputation: happymadman is an unknown quantity at this point 
Solved Threads: 0
happymadman happymadman is offline Offline
Newbie Poster

Threads? help

 
0
  #1
Feb 7th, 2009
Hi, how would I get the timer() class to change time display()'s self.time
I'm new to threads and classes and have been sitting here thinking about it for the last half hour and still have know idea

Thanks heaps for any help.

  1. # Count down timer
  2.  
  3. import time
  4. import threading
  5.  
  6. loop = 1
  7.  
  8. class time_display(object):
  9. def __init__(self):
  10. self.time = 30
  11. def print_time(self):
  12. while self.time > 0:
  13. print self.time
  14. raw_input("Push ENTER to re-check the time")
  15.  
  16. class timer(threading.Thread):
  17. def run(self):
  18. while loop == 1:
  19. time.sleep(1.0)
  20. # Add something here to decrease the time by 1
  21.  
  22.  
  23. timer1 = time_display()
  24. timer2 = timer()
  25. timer2.start()
  26. timer1.print_time()
  27. # I don't know the command to end threads but this sounds right?
  28. timer2.end()
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 11
Reputation: int3grate is an unknown quantity at this point 
Solved Threads: 3
int3grate int3grate is offline Offline
Newbie Poster

Re: Threads? help

 
0
  #2
Feb 8th, 2009
Here's an example I wrote up for you that should be helpful...

  1. import time
  2. import threading
  3.  
  4. time_var = 0
  5.  
  6. class time_display(object):
  7. global time_var
  8. def __init__(self):
  9. global time_var
  10. time_var = 30
  11. def print_time(self):
  12. global time_var
  13. print time_var
  14.  
  15.  
  16. class timer(threading.Thread):
  17. def run(self):
  18. while(True):
  19. global time_var
  20. time.sleep(1.0)
  21. time_var -= 1
  22.  
  23. timer1 = time_display()
  24. timer().start()
  25. while(time_var >= 0):
  26. timer1.print_time()
  27. raw_input("Push ENTER to re-check the time")
  28.  
  29. print "Count down complete..."
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 13
Reputation: happymadman is an unknown quantity at this point 
Solved Threads: 0
happymadman happymadman is offline Offline
Newbie Poster

Re: Threads? help

 
0
  #3
Feb 9th, 2009
Oh, I see.
Thanks heaps.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC