<commit_before>from pyremotecv import PyRemoteCV

from thumbor.detectors import BaseDetector

class QueuedDetector(BaseDetector):
    pyremotecv = None

    def detect(self, callback):
        if not self.pyremotecv:
            self.pyremotecv = PyRemoteCV(host=self.context.config.REDIS_QUEUE_SERVER_HOST,
                                         port=self.context.config.REDIS_QUEUE_SERVER_PORT,
                                         db=self.context.config.REDIS_QUEUE_SERVER_DB,
                                         password=self.context.config.REDIS_QUEUE_SERVER_PASSWORD)
        self.pyremotecv.async_detect('remotecv.pyres_tasks.DetectTask', 'Detect',
                args=[self.detection_type, self.context.request.image_url],
                key=self.context.request.image_url)
        self.context.prevent_result_storage = True
        callback([])<commit_msg>Errors during queued detectors shouldn't prevent the image from being delivered.<commit_after>import traceback

from pyremotecv import PyRemoteCV
from redis import RedisError

from thumbor.detectors import BaseDetector
from thumbor.utils import logger

class QueuedDetector(BaseDetector):
    pyremotecv = None

    def detect(self, callback):
        self.context.prevent_result_storage = True
        try:
            if not self.pyremotecv:
                self.pyremotecv = PyRemoteCV(host=self.context.config.REDIS_QUEUE_SERVER_HOST,
                                             port=self.context.config.REDIS_QUEUE_SERVER_PORT,
                                             db=self.context.config.REDIS_QUEUE_SERVER_DB,
                                             password=self.context.config.REDIS_QUEUE_SERVER_PASSWORD)

            self.pyremotecv.async_detect('remotecv.pyres_tasks.DetectTask', 'Detect',
                    args=[self.detection_type, self.context.request.image_url],
                    key=self.context.request.image_url)
        except RedisError:
            logger.error(traceback.format_exc())
        finally:
            callback([])
{'fraction_non_alphanumeric': 0.07331378299120235, 'fraction_numerical': 0.0, 'mean_word_length': 2.168730650154799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6029496', 'n_tokens_mistral': 566, 'n_tokens_neox': 541, 'n_words': 86}