def event_callable( event ): if HG.menu_profile_mode: summary = 'Profiling menu: ' + repr( callable ) HydrusData.ShowText( summary ) HydrusData.Profile( summary, 'callable( *args, **kwargs )', globals(), locals() ) else: callable( *args, **kwargs )
def Process( self ): # only do one list of callables at a time # we don't want to map a topic to its callables until the previous topic's callables have been fully executed # e.g. when we start a message with a pubsub, it'll take a while (in independant thread-time) for wx to create # the dialog and hence map the new callable to the topic. this was leading to messages not being updated # because the (short) processing thread finished and entirely pubsubbed before wx had a chance to boot the # message. callables = [] with self._lock: if len( self._pubsubs ) > 0: ( topic, args, kwargs ) = self._pubsubs.pop( 0 ) callables = self._GetCallables( topic ) # do this _outside_ the lock, lol for callable in callables: if HydrusGlobals.pubsub_profile_mode: text = 'Profiling ' + topic + ': ' + repr( callable ) if topic == 'message': HydrusData.Print( text ) else: HydrusData.ShowText( text ) HydrusData.Profile( 'callable( *args, **kwargs )', globals(), locals() ) else: try: callable( *args, **kwargs ) except HydrusExceptions.ShutdownException: return
def Process( self ): # only do one list of callables at a time # we don't want to map a topic to its callables until the previous topic's callables have been fully executed # e.g. when we start a message with a pubsub, it'll take a while (in independant thread-time) for wx to create # the dialog and hence map the new callable to the topic. this was leading to messages not being updated # because the (short) processing thread finished and entirely pubsubbed before wx had a chance to boot the # message. self._doing_work = True try: callables = [] with self._lock: if len( self._pubsubs ) == 0: return pubsubs = self._pubsubs self._pubsubs = [] for ( topic, args, kwargs ) in pubsubs: try: callables = self._GetCallables( topic ) # do this _outside_ the lock, lol pubsub_profilable = topic != 'message' if HG.pubsub_profile_mode and pubsub_profilable: summary = 'Profiling ' + HydrusData.ConvertIntToPrettyString( len( callables ) ) + ' x ' + topic HydrusData.ShowText( summary ) per_summary = 'Profiling ' + topic for callable in callables: try: HydrusData.Profile( per_summary, 'callable( *args, **kwargs )', globals(), locals() ) except HydrusExceptions.ShutdownException: return False else: for callable in callables: try: callable( *args, **kwargs ) except HydrusExceptions.ShutdownException: return False except Exception as e: HydrusData.ShowException( e ) finally: self._doing_work = False
def MainLoop(self): try: self._InitDBCursor( ) # have to reinitialise because the thread id has changed self._InitDiskCache() self._InitCaches() except: self._DisplayCatastrophicError(traceback.format_exc()) self._could_not_initialise = True return self._ready_to_serve_requests = True error_count = 0 while not ((self._local_shutdown or self._controller.ModelIsShutdown()) and self._jobs.empty()): try: (priority, job) = self._jobs.get(timeout=1) self._currently_doing_job = True self._current_job_name = job.ToString() self.publish_status_update() try: if HG.db_profile_mode: summary = 'Profiling ' + job.ToString() HydrusData.ShowText(summary) HydrusData.Profile(summary, 'self._ProcessJob( job )', globals(), locals()) else: self._ProcessJob(job) error_count = 0 except: error_count += 1 if error_count > 5: raise self._jobs.put( (priority, job)) # couldn't lock db; put job back on queue time.sleep(5) self._currently_doing_job = False self._current_job_name = '' self.publish_status_update() except Queue.Empty: if self._transaction_contains_writes and HydrusData.TimeHasPassed( self._transaction_started + self.TRANSACTION_COMMIT_TIME): self._Commit() self._BeginImmediate() if HydrusData.TimeHasPassed( self._connection_timestamp + CONNECTION_REFRESH_TIME ): # just to clear out the journal files self._InitDBCursor() self._CleanUpCaches() self._CloseDBCursor() self._loop_finished = True
def MainLoop(self): try: self._InitDBCursor( ) # have to reinitialise because the thread id has changed self._InitCaches() except: HydrusData.Print(traceback.format_exc()) self._could_not_initialise = True return self._ready_to_serve_requests = True error_count = 0 while not ((self._local_shutdown or self._controller.ModelIsShutdown()) and self._jobs.empty()): try: (priority, job) = self._jobs.get(timeout=0.5) self._currently_doing_job = True self._controller.pub('refresh_status') self._pubsubs = [] try: if HydrusGlobals.db_profile_mode: HydrusData.ShowText('Profiling ' + job.ToString()) HydrusData.Profile('self._ProcessJob( job )', globals(), locals()) else: self._ProcessJob(job) error_count = 0 except: error_count += 1 if error_count > 5: raise self._jobs.put( (priority, job)) # couldn't lock db; put job back on queue time.sleep(5) self._currently_doing_job = False self._controller.pub('refresh_status') except Queue.Empty: pass # no jobs in the past little while; let's just check if we should shutdown if HydrusData.TimeHasPassed( self._connection_timestamp + CONNECTION_REFRESH_TIME ): # just to clear out the journal files self._InitDBCursor() self._CleanUpCaches() self._CloseDBCursor() self._loop_finished = True