#!/usr/bin/python # just a thread test import threading import time import sys class PeriodicExecutor(threading.Thread): def __init__(self,sleep,func,*params): """ execute func(params) every 'sleep' seconds """ self.func = func self.params = params self.sleep = sleep threading.Thread.__init__(self,name = "PeriodicExecutor") self.setDaemon(1) def run(self): while 1: time.sleep(self.sleep) apply(self.func,self.params) def fn(): global stuff print 'stuff is',stuff def main(): global stuff print 'hi' arg = 'value' pe = PeriodicExecutor(3,fn) pe.start() for i in range(1000): stuff = i time.sleep(1) sys.exit(0) main()