Example #1
0
 def __init__(self, parameters):
     """
     Instantiates a new backend. Please note that this is called also
     for disabled backends. Those are not initialized, so you might
     want to check out the initialize() function.
     """
     if self.KEY_DEFAULT_BACKEND not in parameters:
         # if it's not specified, then this is the default backend
         #(for retro-compatibility with the GTG 0.2 series)
         parameters[self.KEY_DEFAULT_BACKEND] = True
     # default backends should get all the tasks
     if parameters[self.KEY_DEFAULT_BACKEND] or \
             (not self.KEY_ATTACHED_TAGS in parameters and
              self._general_description[self.BACKEND_TYPE]
              == self.TYPE_READWRITE):
         parameters[self.KEY_ATTACHED_TAGS] = [self.ALLTASKS_TAG]
     self._parameters = parameters
     self._signal_manager = BackendSignals()
     self._is_initialized = False
     # if debugging mode is enabled, tasks should be saved as soon as
     # they're marked as modified. If in normal mode, we prefer speed over
     # easier debugging.
     if Log.is_debugging_mode():
         self.timer_timestep = 5
     else:
         self.timer_timestep = 1
     self.to_set_timer = None
     self.please_quit = False
     self.cancellation_point = lambda: _cancellation_point(lambda: self.
                                                           please_quit)
     self.to_set = deque()
     self.to_remove = deque()
Example #2
0
 def __init__(self, parameters):
     """
     Instantiates a new backend. Please note that this is called also
     for disabled backends. Those are not initialized, so you might
     want to check out the initialize() function.
     """
     if self.KEY_DEFAULT_BACKEND not in parameters:
         # if it's not specified, then this is the default backend
         #(for retro-compatibility with the GTG 0.2 series)
         parameters[self.KEY_DEFAULT_BACKEND] = True
     # default backends should get all the tasks
     if parameters[self.KEY_DEFAULT_BACKEND] or \
             (not self.KEY_ATTACHED_TAGS in parameters and
              self._general_description[self.BACKEND_TYPE]
              == self.TYPE_READWRITE):
         parameters[self.KEY_ATTACHED_TAGS] = [self.ALLTASKS_TAG]
     self._parameters = parameters
     self._signal_manager = BackendSignals()
     self._is_initialized = False
     # if debugging mode is enabled, tasks should be saved as soon as
     # they're marked as modified. If in normal mode, we prefer speed over
     # easier debugging.
     if Log.is_debugging_mode():
         self.timer_timestep = 5
     else:
         self.timer_timestep = 1
     self.to_set_timer = None
     self.please_quit = False
     self.cancellation_point = lambda: _cancellation_point(
         lambda: self.please_quit)
     self.to_set = deque()
     self.to_remove = deque()
Example #3
0
    def test_interruptible_decorator(self):
        """ Tests for the @interruptible decorator. """
        thread = Thread(target=self.never_ending, args=(
            lambda: _cancellation_point(lambda: self.quit_condition),))
        thread.start()

        # Wait until thread comes to live
        self.thread_started.wait()

        # Ask to it to quit within 20ms
        self.quit_condition = True
        time.sleep(0.02)

        # Thread is finished
        self.assertFalse(thread.is_alive())
Example #4
0
    def test_interruptible_decorator(self):
        """ Tests for the @interruptible decorator. """
        cancellation_point = lambda: _cancellation_point(
            lambda: self.quit_condition)
        thread = Thread(target=self.never_ending, args=(cancellation_point,))
        thread.start()

        # Wait until thread comes to live
        self.thread_started.wait()

        # Ask to it to quit within 20ms
        self.quit_condition = True
        time.sleep(0.02)

        # Thread is finished
        self.assertFalse(thread.is_alive())
Example #5
0
    def test_interruptible_decorator(self):
        """ Tests for the @interruptible decorator. """
        self.quit_condition = False
        cancellation_point = lambda: _cancellation_point(
            lambda: self.quit_condition)
        self.thread_started = Event()

        @interruptible
        def never_ending(cancellation_point):
            self.thread_started.set()
            while True:
                time.sleep(0.1)
                cancellation_point()
        thread = Thread(target=never_ending, args=(cancellation_point, ))
        thread.start()
        self.thread_started.wait()
        self.quit_condition = True
        countdown = 10
        while thread.is_alive() and countdown > 0:
            time.sleep(0.1)
            countdown -= 1
        self.assertFalse(thread.is_alive())