changed from event to Queue.Queue, still not working...
This commit is contained in:
parent
7b71188854
commit
c604d4da4d
2 changed files with 19 additions and 6 deletions
|
|
@ -115,7 +115,6 @@ def main():
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
task = TaskExecutor.Instance()
|
task = TaskExecutor.Instance()
|
||||||
logger.debug("blah")
|
|
||||||
#logger.debug("task executor instance :%s", str(task))
|
#logger.debug("task executor instance :%s", str(task))
|
||||||
|
|
||||||
job_count = 0
|
job_count = 0
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
|
from Queue import Queue
|
||||||
from linspector.utils.singleton import Singleton
|
from linspector.utils.singleton import Singleton
|
||||||
|
|
||||||
KEY_TYPE = "type"
|
KEY_TYPE = "type"
|
||||||
|
|
@ -79,7 +80,7 @@ class TaskExecutor(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
logger.debug("init taskExecutor")
|
logger.debug("init taskExecutor")
|
||||||
self.event = Event()
|
self.event = Event()
|
||||||
self.taskInfos = []
|
self.taskInfos = Queue()
|
||||||
task_thread = Thread(target=self._run_worker_thread)
|
task_thread = Thread(target=self._run_worker_thread)
|
||||||
self._instantEnd = False
|
self._instantEnd = False
|
||||||
self._running = True
|
self._running = True
|
||||||
|
|
@ -87,7 +88,9 @@ class TaskExecutor(object):
|
||||||
task_thread.start()
|
task_thread.start()
|
||||||
|
|
||||||
def _run_worker_thread(self):
|
def _run_worker_thread(self):
|
||||||
|
logger.debug("start running taskExcecutor worker Thread")
|
||||||
while self.is_running() or not self.is_instant_end():
|
while self.is_running() or not self.is_instant_end():
|
||||||
|
'''
|
||||||
if len(self.taskInfos) == 0:
|
if len(self.taskInfos) == 0:
|
||||||
logger.debug("waiting for jobs to add")
|
logger.debug("waiting for jobs to add")
|
||||||
self.event.clear()
|
self.event.clear()
|
||||||
|
|
@ -104,6 +107,14 @@ class TaskExecutor(object):
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error("Error " + str(e))
|
logger.error("Error " + str(e))
|
||||||
|
'''
|
||||||
|
try:
|
||||||
|
logger.debug("try to get queued task")
|
||||||
|
msg, task = self.taskInfos.get()
|
||||||
|
logger.debug("got task %s for msg: %s", str(task), str(msg))
|
||||||
|
task.execute(msg)
|
||||||
|
except Exception, e:
|
||||||
|
logger.error("Error " + str(e))
|
||||||
logger.debug("shutting down TaskExecutor!")
|
logger.debug("shutting down TaskExecutor!")
|
||||||
|
|
||||||
def is_instant_end(self):
|
def is_instant_end(self):
|
||||||
|
|
@ -122,7 +133,10 @@ class TaskExecutor(object):
|
||||||
self.event.set()
|
self.event.set()
|
||||||
|
|
||||||
def schedule_task(self, msg, task):
|
def schedule_task(self, msg, task):
|
||||||
|
try:
|
||||||
logger.debug("appending task '%s' for msg: %s", str(task), str(msg))
|
logger.debug("appending task '%s' for msg: %s", str(task), str(msg))
|
||||||
self.taskInfos.append((msg, task))
|
self.taskInfos.put((msg, task))
|
||||||
logger.debug("%s task stored", str(len(self.taskInfos)))
|
except Exception, e:
|
||||||
self.event.set()
|
logger.debug("queue is probably full: %s", str(e))
|
||||||
|
#logger.debug("%s task Queued", str(len(self.taskInfos)))
|
||||||
|
#self.event.set()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue