Using Timer or Scheduler in a Class

Prof. William Battersea williambattersea at gmail.com
Wed Aug 13 23:16:12 EDT 2008


I'd like a class method to fire every n seconds.

I tried this:

class Timed:
    def.__init__(self):
        self.t = Timer(3, self.dothing)

    def.start(self):
        self.t.start()

    def.dothing(self):
        print "Doing Thing"

s = new Timed()
s.start()

And:

class Scheduled:
    def.__init__(self):
        self.s = sched.scheduler(time.time, time.sleep)
        self.s.enter(3, 1, self.sync, ())

    def.start(self):
        self.t.start()

    def.dothing(self):
        print "Syncing"

s = new Scheduled()
s.start()

Both run once and end. I'm obviously missing something here.

Thanks,

Justin



More information about the Python-list mailing list