954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Threads? help

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.

# Count down timer

import time
import threading

loop = 1

class time_display(object):
    def __init__(self):
        self.time = 30
    def print_time(self):
        while self.time > 0:
            print self.time
            raw_input("Push ENTER to re-check the time")

class timer(threading.Thread):
    def run(self):
        while loop == 1:
            time.sleep(1.0)
            # Add something here to decrease the time by 1
            

timer1 = time_display()
timer2 = timer()
timer2.start()
timer1.print_time()
# I don't know the command to end threads but this sounds right?
timer2.end()
happymadman
Newbie Poster
24 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

Here's an example I wrote up for you that should be helpful...

import time
import threading

time_var = 0

class time_display(object):
    global time_var
    def __init__(self):
        global time_var
        time_var = 30
    def print_time(self):
        global time_var
        print time_var

        
class timer(threading.Thread):
    def run(self):
        while(True):
            global time_var
            time.sleep(1.0)
            time_var -= 1

timer1 = time_display()
timer().start()
while(time_var >= 0):
    timer1.print_time()
    raw_input("Push ENTER to re-check the time")

print "Count down complete..."
int3grate
Newbie Poster
11 posts since Jan 2009
Reputation Points: 16
Solved Threads: 3
 

Oh, I see.
Thanks heaps.

happymadman
Newbie Poster
24 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You