aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scratchpad.py31
1 files 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