Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a loop time and runOnce method.
Most of the discoverers will be run in a loop, so it makes
sense to have the loop built in to the base class.
  • Loading branch information
bitplane committed Apr 3, 2012
1 parent 97ca549 commit 293390a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Discoverer.py
Expand Up @@ -2,6 +2,7 @@
to load all the available discovery modules.
"""

from time import sleep
from threading import Thread

class Discoverer(Thread):
Expand All @@ -28,14 +29,24 @@ class Discoverer(Thread):

def __init__(self, output):
"""Construct a new Discoverer
output: a queue where the output will be pushed."""
output: a queue where the output will be pushed.
loopTime: the amount of time to sleep for between loops."""
Thread.__init__(self)
self.output = output
self.output = output
self.loopTime = loopTime

def run(self):
"""Runs this detector forever in a loop.
Override this method if your discoverer already loops
forever.
"""
while True:
self.runOnce()
sleep(self.loopTime)

def runOnce(self):
"""The main loop of the discoverer.
Do your thing in here, loop forever and pass things
to the output queue.
Override this method and do your thing in here.
"""
pass

0 comments on commit 293390a

Please sign in to comment.