def st_callback_wrapper(self, func):
        """add shutdown checker for origin callback function."""

        @wraps(func)
        def wrapper(r):
            # if tries end or timeout or shutdown_changed => shutdown
            result = func(r)
            self.counter.x
            succ = result == self.original_response
            if self.counter.now >= self.total_tries:
                print_info('shutdown for: total_tries: %s' % self.total_time)
                self.shutdown()
            if self.passed >= self.total_time:
                print_info('shutdown for: total_time: %s' % self.total_time)
                self.shutdown()
            if succ:
                self.succ_counter.x
            elif self.shutdown_changed:
                print_info('shutdown for: shutdown_changed: %s => %s' %
                           (self.original_response, result))
                self.shutdown()
            self.logger_function(result, cost=time.time() - r.task_start_time)
            return result

        return wrapper
def st_callback_wrapper ( self , func ) : @ wraps ( func ) def wrapper ( r ) : result = func ( r ) self . counter . x succ = result == self . original_response if self . counter . now >= self . total_tries : print_info ( 'shutdown for: total_tries: %s' % self . total_time ) self . shutdown ( ) if self . passed >= self . total_time : print_info ( 'shutdown for: total_time: %s' % self . total_time ) self . shutdown ( ) if succ : self . succ_counter . x elif self . shutdown_changed : print_info ( 'shutdown for: shutdown_changed: %s => %s' % ( self . original_response , result ) ) self . shutdown ( ) self . logger_function ( result , cost = time . time ( ) - r . task_start_time ) return result return wrapper
add shutdown checker for origin callback function.