Exemple #1
0
 def event_callable( checked_state ):
     
     if HG.menu_profile_mode:
         
         summary = 'Profiling menu: ' + repr( callable )
         
         HydrusData.Profile( summary, 'callable( *args, **kwargs )', globals(), locals(), min_duration_ms = 3, show_summary = True )
         
     else:
         
         callable( *args, **kwargs )
Exemple #2
0
    def event_callable(checked_state):

        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)
Exemple #3
0
    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 Qt 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 Qt had a chance to boot the
        # message.

        self._doing_work = True

        try:

            callable_tuples = []

            with self._lock:

                if len(self._pubsubs) == 0:

                    return

                pubsubs = self._pubsubs

                self._pubsubs = []

            for (topic, args, kwargs) in pubsubs:

                try:

                    # do all this _outside_ the lock, lol

                    callable_tuples = self._GetCallableTuples(topic)

                    # don't want to report the showtext we just send here!
                    not_a_report = topic != 'message'

                    if HG.pubsub_report_mode and not_a_report:

                        HydrusData.ShowText(
                            (topic, args, kwargs, callable_tuples))

                    if HG.pubsub_profile_mode and not_a_report:

                        summary = 'Profiling ' + HydrusData.ToHumanInt(
                            len(callable_tuples)) + ' x ' + topic

                        HydrusData.ShowText(summary)

                        per_summary = 'Profiling ' + topic

                        for (obj, callable) in callable_tuples:

                            try:

                                HydrusData.Profile(
                                    per_summary, 'callable( *args, **kwargs )',
                                    globals(), locals())

                            except HydrusExceptions.ShutdownException:

                                return False

                    else:

                        for (obj, callable) in callable_tuples:

                            try:

                                callable(*args, **kwargs)

                            except HydrusExceptions.ShutdownException:

                                return False

                except Exception as e:

                    HydrusData.ShowException(e)

        finally:

            self._doing_work = False
Exemple #4
0
    def run(self):

        try:

            while True:

                while self._queue.empty():

                    CheckIfThreadShuttingDown()

                    self._event.wait(10.0)

                    self._event.clear()

                CheckIfThreadShuttingDown()

                try:

                    try:

                        (callable, args, kwargs) = self._queue.get(1.0)

                    except queue.Empty:

                        # https://github.com/hydrusnetwork/hydrus/issues/750
                        # this shouldn't happen, but...
                        # even if we assume we'll never get this, we don't want to make a business of hanging forever on things

                        continue

                    self._DoPreCall()

                    self._callable = (callable, args, kwargs)

                    if HG.callto_profile_mode:

                        summary = 'Profiling CallTo Job: {}'.format(callable)

                        HydrusData.Profile(summary,
                                           'callable( *args, **kwargs )',
                                           globals(),
                                           locals(),
                                           min_duration_ms=3,
                                           show_summary=True)

                    else:

                        callable(*args, **kwargs)

                    self._callable = None

                    del callable

                except HydrusExceptions.ShutdownException:

                    return

                except Exception as e:

                    HydrusData.Print(traceback.format_exc())

                    HydrusData.ShowException(e)

                finally:

                    self._currently_working = False

                time.sleep(0.00001)

        except HydrusExceptions.ShutdownException:

            return
Exemple #5
0
 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 HG.model_shutdown ) and self._jobs.empty() ):
         
         try:
             
             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_report_mode:
                     
                     summary = 'Running ' + job.ToString()
                     
                     HydrusData.ShowText( summary )
                     
                 
                 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( 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()
                 
                 self._transaction_contains_writes = False
                 
             
         
         if HydrusData.TimeHasPassed( self._connection_timestamp + CONNECTION_REFRESH_TIME ): # just to clear out the journal files
             
             self._InitDBCursor()
             
         
         if self._pause_and_disconnect:
             
             self._CloseDBCursor()
             
             while self._pause_and_disconnect:
                 
                 if self._local_shutdown or HG.model_shutdown:
                     
                     break
                     
                 
                 time.sleep( 1 )
                 
             
             self._InitDBCursor()
             
         
     
     self._CleanUpCaches()
     
     self._CloseDBCursor()
     
     temp_path = os.path.join( self._db_dir, self._durable_temp_db_filename )
     
     HydrusPaths.DeletePath( temp_path )
     
     self._loop_finished = True
    def MainLoop(self):

        try:

            self._InitDBCursor(
            )  # have to reinitialise because the thread id has changed

            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 HG.model_shutdown)
                   and self._jobs.empty()):

            try:

                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_report_mode:

                        summary = 'Running ' + job.ToString()

                        HydrusData.ShowText(summary)

                    if HG.db_profile_mode:

                        summary = 'Profiling ' + job.ToString()

                        HydrusData.Profile(summary,
                                           'self._ProcessJob( job )',
                                           globals(),
                                           locals(),
                                           show_summary=True)

                    else:

                        self._ProcessJob(job)

                    error_count = 0

                except:

                    error_count += 1

                    if error_count > 5:

                        raise

                    self._jobs.put(
                        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._cursor_transaction_wrapper.TimeToCommit():

                    self._cursor_transaction_wrapper.CommitAndBegin()

            if self._pause_and_disconnect:

                self._CloseDBCursor()

                while self._pause_and_disconnect:

                    if self._local_shutdown or HG.model_shutdown:

                        break

                    time.sleep(1)

                self._InitDBCursor()

        self._CloseDBCursor()

        temp_path = os.path.join(self._db_dir, self._durable_temp_db_filename)

        HydrusPaths.DeletePath(temp_path)

        self._loop_finished = True