def run( self ): self._event.wait( self._init_wait ) while True: if HC.shutdown: return time.sleep( self._pre_callable_wait ) while HC.app.JustWokeFromSleep(): if HC.shutdown: return time.sleep( 10 ) try: self._callable() except Exception as e: HC.ShowText( 'Daemon ' + self._name + ' encountered an exception:' ) HC.ShowException( e ) if HC.shutdown: return self._event.wait( self._period ) self._event.clear()
def run( self ): time.sleep( 3 ) while True: while self._queue.empty(): if HC.shutdown: return self._event.wait( self._period ) self._event.clear() while HC.app.JustWokeFromSleep(): if HC.shutdown: return time.sleep( 10 ) items = [] while not self._queue.empty(): items.append( self._queue.get() ) try: self._callable( items ) except Exception as e: HC.ShowException( e )
def THREADRender( self ): num_frames = self._media.GetNumFrames() while True: time.sleep( 0.00001 ) # thread yield with self._render_lock: if not self._rendered_first_frame or self._next_render_index != ( self._render_to_index + 1 ) % num_frames: self._rendered_first_frame = True frame_index = self._next_render_index # keep this before the get call, as it increments in a clock arithmetic way afterwards try: numpy_image = self._renderer.read_frame() except Exception as e: HC.ShowException( e ) break finally: self._next_render_index = ( self._next_render_index + 1 ) % num_frames frame = HydrusImageHandling.GenerateHydrusBitmapFromNumPyImage( numpy_image ) wx.CallAfter( self.AddFrame, frame_index, frame ) else: break
def THREADDoFileQuery(self, query_key, search_context): try: query_hash_ids = self.Read('file_query_ids', search_context) query_hash_ids = list(query_hash_ids) random.shuffle(query_hash_ids) limit = search_context.GetSystemPredicates().GetLimit() if limit is not None: query_hash_ids = query_hash_ids[:limit] service_key = search_context.GetFileServiceKey() include_current_tags = search_context.IncludeCurrentTags() media_results = [] include_pending_tags = search_context.IncludePendingTags() i = 0 base = 256 while i < len(query_hash_ids): if query_key.IsCancelled(): return if i == 0: (last_i, i) = (0, base) else: (last_i, i) = (i, i + base) sub_query_hash_ids = query_hash_ids[last_i:i] more_media_results = self.Read('media_results_from_ids', service_key, sub_query_hash_ids) media_results.extend(more_media_results) HC.pubsub.pub('set_num_query_results', len(media_results), len(query_hash_ids)) self.WaitUntilGoodTimeToUseGUIThread() HC.pubsub.pub('file_query_done', query_key, media_results) except Exception as e: HC.ShowException(e)
def run( self ): while True: while self._queue.empty(): if HC.shutdown: return self._event.wait( 1200 ) self._event.clear() try: ( callable, args, kwargs ) = self._queue.get() callable( *args, **kwargs ) del callable except Exception as e: HC.ShowException( e ) time.sleep( 0.00001 )