Exemplo n.º 1
0
    def test_stop(self):

        Control.stop(1)
        # Validate...
        a, b, path = Control.get_last_set_data()
        self.assertFalse(a)
        self.assertFalse(b)
        self.assertEqual(1, path)
Exemplo n.º 2
0
    def run(self):

        """The thread `run()` method. We simply sit on the back-end of the
        queue and process actions as they arrive. The `terminate` action
        causes the `run()` method to exit.

        As actions are processed the number of pending (put but unprocessed)
        actions is decremented."""

        while self.running:

            # Get from the queue, blocking until something is retrieved.
            item = self.action_queue.get()
            assert isinstance(item, PathAction),\
                "Invalid object on action_queue (%s)" % item

            # Process the action...
            if item == PathAction.go:

                # Traffic to be set to 'go' on this path
                Control.go(self.path)

            elif item == PathAction.stop:

                # Traffic to be set to 'stop' on this path
                Control.stop(self.path)

            elif item == PathAction.terminate:

                # The 'kill' event -
                # stop processing and exit the run-loop
                self.running = False

            # The action has been processed,
            # safely decrement the number of pending actions.
            self._dec_pending()