[Tutor] Threading a Class?

Britt Green britt_green@hotmail.com
Mon, 09 Jul 2001 09:57:44 -0700


Alright, I think I have the basics of my Time class going the way I want it 
to. Now I need to make it threaded. This is what I have so far:

import time

class GameTime:
    def __init__(self):
        print "Class GameTime initiated."

    def updateTime(self):
        while 1:
            self.theTime = time.ctime(time.time())
            print self.theTime
            time.sleep( 20 )

myTime = GameTime()
myTime.updateTime()

The time.sleep() function causes my program to, well, sleep for twenty 
seconds and during that time my program can do nothing else. I'd like to put 
this in a thread so that other things can be executed while the timer is 
sleeping.

Unfortunately, I'm kind of stuck on how to do this. I've gotten pointed in 
the right direction by a couple of books, but because this is the first time 
I've written anything involving threads, I could really use some 
step-by-step instruction on this.

Many thanks!

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com