示例#1
0
文件: nfpm.py 项目: ktsitsikas/odemis
 def _createFuture(self):
     """
     Return (CancellableFuture): a future that can be used to manage a move
     """
     f = CancellableFuture()
     f._moving_lock = threading.Lock() # taken while moving
     f._must_stop = threading.Event() # cancel of the current future requested
     f._was_stopped = False # if cancel was successful
     f.task_canceller = self._cancelCurrentMove
     return f
示例#2
0
 def test_execute(self):
     f = CancellableFuture()
     t = executeAsyncTask(f, self.long_task, args=(42,), kwargs={"d": 3})
     self.assertFalse(f.done())
     time.sleep(0.1)
     self.assertTrue(f.running())
     r = f.result()
     self.assertEqual(r, -1)
     self.assertEqual(self._v, 42)
     self.assertEqual(self._d, 3)
示例#3
0
 def test_execute(self):
     f = CancellableFuture()
     t = executeAsyncTask(f, self.long_task, args=(42, ), kwargs={"d": 3})
     self.assertFalse(f.done())
     time.sleep(0.1)
     self.assertTrue(f.running())
     r = f.result()
     self.assertEqual(r, -1)
     self.assertEqual(self._v, 42)
     self.assertEqual(self._d, 3)
示例#4
0
文件: light.py 项目: delmic/odemis
def turnOnLight(bl, ccd):
    """
    Turn on a light and wait until it detects a signal change on the ccd
    bl (Light): the light, which should initially be turned off.
    ccd (DigitalCamera): detector to use to check for the signal
    returns (CancellableFuture): a future that will finish when a significant
      signal increase is detected. Can also be used to stop the procedure. 
    """
    f = CancellableFuture()
    f.task_canceller = _cancelTurnOnLight
    f._task_state = RUNNING
    f._task_lock = threading.Lock()
    f._was_stopped = False  # if cancel was successful
    # Run in separate thread
    executeAsyncTask(f, _doTurnOnLight, args=(f, bl, ccd))
    return f
示例#5
0
    def _createFuture(self, axes, update):
        """
        Return (CancellableFuture): a future that can be used to manage a move
        axes (set of str): the axes that are moved
        update (bool): if it's an update move
        """
        # TODO: do this via the __init__ of subclass of Future?
        f = CancellableFuture()  # TODO: make it cancellable too

        f._update_axes = set()  # axes handled by the move, if update
        if update:
            # Check if all the axes support it
            if all(self.axes[a].canUpdate for a in axes):
                f._update_axes = axes
            else:
                logging.warning("Trying to do a update move on axes %s not supporting update", axes)

        return f
示例#6
0
    def _createFuture(self, axes, update):
        """
        Return (CancellableFuture): a future that can be used to manage a move
        axes (set of str): the axes that are moved
        update (bool): if it's an update move
        """
        # TODO: do this via the __init__ of subclass of Future?
        f = CancellableFuture()  # TODO: make it cancellable too

        f._update_axes = set()  # axes handled by the move, if update
        if update:
            # Check if all the axes support it
            if all(self.axes[a].canUpdate for a in axes):
                f._update_axes = axes
            else:
                logging.warning("Trying to do a update move on axes %s not supporting update", axes)

        return f
示例#7
0
文件: zeiss.py 项目: Mahmood-B/odemis
 def _createFuture(self):
     """
     Return (CancellableFuture): a future that can be used to manage a move
     """
     f = CancellableFuture()
     f._moving_lock = threading.Lock()  # taken while moving
     f._must_stop = threading.Event()  # cancel of the current future requested
     f._was_stopped = False  # if cancel was successful
     f.task_canceller = self._cancelCurrentMove
     return f
示例#8
0
 def _createMoveFuture(self, ref=False):
     """
     ref: if true, will use a different canceller
     Return (CancellableFuture): a future that can be used to manage a move
     """
     f = CancellableFuture()
     f._moving_lock = threading.Lock()  # taken while moving
     f._must_stop = threading.Event(
     )  # cancel of the current future requested
     f._was_stopped = False  # if cancel was successful
     if not ref:
         f.task_canceller = self._cancelCurrentMove
     else:
         f.task_canceller = self._cancelReference
     return f
示例#9
0
def turnOnLight(bl, ccd):
    """
    Turn on a light and wait until it detects a signal change on the ccd
    bl (Light): the light, which should initially be turned off.
    ccd (DigitalCamera): detector to use to check for the signal
    returns (CancellableFuture): a future that will finish when a significant
      signal increase is detected. Can also be used to stop the procedure. 
    """
    f = CancellableFuture()
    f.task_canceller = _cancelTurnOnLight
    f._task_state = RUNNING
    f._task_lock = threading.Lock()
    f._was_stopped = False  # if cancel was successful
    # Run in separate thread
    executeAsyncTask(f, _doTurnOnLight, args=(f, bl, ccd))
    return f