コード例 #1
0
    def inner(func):
        logger.debug("Semaphore for {} -> {}".format(func, semaphore))

        @wraps(func)
        def wrapper(*args, **kwargs):
            try:
                logger.info("==> {}::Acquire Semaphore ...".format(
                    func.__name__))
                semaphore.acquire()
                return func(*args, **kwargs)
            finally:
                logger.info("<== {}::Release Semaphore ...".format(
                    func.__name__))
                semaphore.release()

        return wrapper
コード例 #2
0
def synchronized(func, max_connections=2):
    """Synchronize function call via semaphore
    """
    semaphore = threading.BoundedSemaphore(max_connections)
    logger.debug("Semaphore for {} -> {}".format(func, semaphore))

    def decorator(*args, **kwargs):
        try:
            logger.info("==> {}::Acquire Semaphore ...".format(func.__name__))
            semaphore.acquire()
            return func(*args, **kwargs)
        finally:
            logger.info("<== {}::Release Semaphore ...".format(func.__name__))
            semaphore.release()

    return decorator
コード例 #3
0
    def to_model(self, uid):
        """Returns a SuperModel for the given UID
        """
        model = None
        # Fetch the report (portal-) type for component lookups
        _type = self.get_report_type()
        try:
            model = getAdapter(uid, ISuperModel, name=_type)
        except ComponentLookupError:
            logger.error(
                "Lookup Error: No SuperModel registered for name={}".format(
                    _type))
            model = getAdapter(uid, ISuperModel)

        logger.debug("Created Model for UID={}->{}".format(uid, model))
        return model