Example #1
0
    def wrapper(*args):
        while True:
            sleep_amount = loop_function(*args)
            if (sleep_amount == 'break'): break
            elif (not sleep_amount): continue

            fast_sleep(sleep_amount)
Example #2
0
    def wait_in_line(self, position):
        '''blocking call to wait for all lower number threads to complete before checking in and returning.

        this call has the potential to deadlock. positions must be sequential work as intended, but are not
        required to be called in order.

        '''
        if (not self._is_initializing): return

        while not position == len(self._thread_ready):
            fast_sleep(1)
Example #3
0
 def _looper(self, instance):
     '''waiting for job to become available. once available the, event will be reset
     and the decorated function will be called with the return of queue pop as an
     argument. runs forever.'''
     self._Log.debug(f'{self._name}/{self.__class__.__name__} started.')
     while True:
         self._job_available.wait()
         # processing all available jobs
         self._job_available.clear()
         while self._queue:
             try:
                 job = self._queue.popleft()
                 self._func(instance, job)
             except Exception as E:
                 self._Log.warning(
                     f'error while processing a {self._name}/{self.__class__.__name__} job. | {E}'
                 )
                 fast_sleep(.001)
Example #4
0
    def wait_for_threads(self, *, count, timeout=None):
        '''will block until the checked in thread count has reach the sent in count.'''
        if (not self._is_initializing or self.has_ran):
            raise RuntimeError('run has already been called for this self.')

        self._thread_count = count
        self._timeout = timeout

        self._Log.notice(f'{self._name} setup waiting for threads: {count}.')

        # blocking until all threads check in by individually calling done method
        while not self._initial_load_complete:
            fast_sleep(1)

        self.has_ran = True
        self._is_initializing = False
        self._thread_ready = None

        self._Log.notice(f'{self._name} setup complete.')
Example #5
0
        def wrapper(*args):
            if (Log):
                Log.debug(f'{name}/dnx_queue started.')

            while True:
                job_wait()
                # clearing job notification
                job_clear()
                # processing all available jobs
                while queue:
                    job = queue_get()
                    try:
                        # TODO: see if we should just send in the queue reference and perform the pop in the called func. if
                        # we do this we would probably want it to be optional and use a conditional set on start to identify.
                        func(*args, job)
                    except Exception as E:
                        if (Log):
                            Log.warning(
                                f'error while processing a {name}/dnx_queue started job. | {E}'
                            )

                        fast_sleep(MSEC)
Example #6
0
        def wrapper(*args):
            while True:
                loop_function(*args)

                if (sleep_len):
                    fast_sleep(sleep_len)