From 1767c392685afa763fd9221f25e73ee76948bd35 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Mon, 5 Dec 2011 17:59:04 +0100 Subject: scratchpad.py --- scratchpad.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/scratchpad.py b/scratchpad.py index e5aac7b..cf2db27 100644 --- a/scratchpad.py +++ b/scratchpad.py @@ -69,19 +69,34 @@ class ActionExecuter(threading.Thread) class MotionControl(object): def __init__(self, name): + import weakref, threading self.name = name + self.on_cycle_started = Signal() + self.on_cycle_finished = Signal() + self.on_cycle_aborted = Signal() + + def __del__(self): + + def start_cycle(self): self.active = True - self.worker_thread = threading.Thread(target = self.workerLoop, name = "MotionControl.worker_thread") - self.worker_thread.setDaemon(True) + self.worker_thread = threading.Thread(target = MotionControl.cycle_threadfunction, name = "MotionControl.worker_thread"), args=(weakref.proxy(self),)) + self.worker_thread.daemon =True self.worker_thread.start() + self.on_cycle_started.send() - def __del__(self): + def abort(self): + self.active = False + self.worker_thread.join() - def workerLoop(self): - import time - while self.active: - print self.name - time.sleep(1) + def cycle_threadfunction(ref): + try: + import time + while ref.active: + print self.name + time.sleep(1) + ref.on_cycle_finished.send() + except: + ref.on_cycle_aborted.send() import threading import rpyc -- cgit v1.2.3