Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I change this thread code to pass params

Status
Not open for further replies.

no137

Programmer
Feb 5, 2002
7
US
How can I change this thread code to pass params?


import threading


class TaskThread(threading.Thread):
"""Thread that executes a task every N seconds"""

def __init__(self):
threading.Thread.__init__(self)
self._finished = threading.Event()
self._interval = 15.0

def setInterval(self, interval):
"""Set the number of seconds we sleep between executing our task"""
self._interval = interval

def shutdown(self):
"""Stop this thread"""
self._finished.set()

def run(self):
while 1:
if self._finished.isSet(): return
self.task()

# sleep for interval or until shutdown
self._finished.wait(self._interval)

def task(self):
"""The task done by this thread - override in subclasses"""
pass

Can someone help.

Thanks
Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top