def _GetCallToThread( self ): with self._call_to_thread_lock: for call_to_thread in self._call_to_threads: if not call_to_thread.CurrentlyWorking(): return call_to_thread # all the threads in the pool are currently busy calling_from_the_thread_pool = threading.current_thread() in self._call_to_threads if calling_from_the_thread_pool or len( self._call_to_threads ) < 200: call_to_thread = HydrusThreading.THREADCallToThread( self, 'CallToThread' ) self._call_to_threads.append( call_to_thread ) call_to_thread.start() else: call_to_thread = random.choice( self._call_to_threads ) return call_to_thread
def _GetCallToThreadLongRunning(self): with self._call_to_thread_lock: for call_to_thread in self._long_running_call_to_threads: if not call_to_thread.CurrentlyWorking(): return call_to_thread call_to_thread = HydrusThreading.THREADCallToThread( self, 'CallToThreadLongRunning') self._long_running_call_to_threads.append(call_to_thread) call_to_thread.start() return call_to_thread
def _GetCallToThread(self): for call_to_thread in self._call_to_threads: if not call_to_thread.CurrentlyWorking(): return call_to_thread if len(self._call_to_threads) > 100: raise Exception('Too many call to threads!') call_to_thread = HydrusThreading.THREADCallToThread( self, 'CallToThread') self._call_to_threads.append(call_to_thread) call_to_thread.start() return call_to_thread