当前位置: 首页>>代码示例>>Python>>正文


Python lock.Semaphore方法代码示例

本文整理汇总了Python中gevent.lock.Semaphore方法的典型用法代码示例。如果您正苦于以下问题:Python lock.Semaphore方法的具体用法?Python lock.Semaphore怎么用?Python lock.Semaphore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gevent.lock的用法示例。


在下文中一共展示了lock.Semaphore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, db, expand_targets, message_send_enqueue, sender_app):
        self.db = db
        self.expand_targets = expand_targets
        self.message_send_enqueue = message_send_enqueue
        self.iris_application = None
        if sender_app:
            self.iris_application = iris.cache.applications.get(sender_app)
            if self.iris_application:
                logger.info('Using iris application (%s) for sender quota notifications.', sender_app)
            else:
                logger.error('Invalid iris application (%s) used for sender. Quota breach notificiations/incidents will not work.', sender_app)
        else:
            logger.warning('Iris sender_app not configured so notifications for quota breaches will not work')

        self.rates = {}  # application: (hard_buckets, soft_buckets, hard_limit, soft_limit, wait_time, plan_name, (target_name, target_role))
        self.last_incidents = {}  # application: (incident_id, time())
        self.last_incidents_mutex = Semaphore()
        self.last_soft_quota_notification_time = {}  # application: time()
        self.last_soft_quota_notification_time_mutex = Semaphore()
        metrics.add_new_metrics({'quota_hard_exceed_cnt': 0, 'quota_soft_exceed_cnt': 0})
        spawn(self.refresh) 
开发者ID:linkedin,项目名称:iris,代码行数:23,代码来源:quota.py

示例2: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, tree_hub, application_name, type_name, semaphore=None):
        assert type_name in ('service', 'switch', 'config')

        self.hub = tree_hub
        self.application_name = application_name
        self.type_name = type_name
        self.path = make_path(self.hub.base_path, type_name, application_name)
        self.cache = make_cache(self.hub.client, self.path)
        self.initialized = Event()
        self._started = False
        self._closed = False
        self.cluster_resolver = ClusterResolver(
            self.get_service_info, self.get_cluster_info)
        if semaphore is None:
            self.throttle_semaphore = Semaphore()
        else:
            self.throttle_semaphore = semaphore 
开发者ID:huskar-org,项目名称:huskar,代码行数:19,代码来源:holder.py

示例3: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, *args, **kwargs):
        ImapSyncMonitor.__init__(self, *args, **kwargs)
        self.sync_engine_class = GmailFolderSyncEngine

        # We start a label refresh whenever we find a new labels
        # However, this is a pretty expensive operation, so we
        # use a semaphore to make sure we're not running multiple
        # LabelRenameHandlers for a single account.
        # This is a conservative choice which should be okay most
        # of the time.
        # We could have used something like a table to not start
        # a LabelRenameHandler for a label when another one is
        # already running, but in some cases it gives us better consistency
        # (e.g: I have a label A -> I rename to B, then to C but add some
        #       labels back into A).
        # This is unlikely but worth getting right.
        # - karim
        self.label_rename_semaphore = Semaphore(value=1) 
开发者ID:nylas,项目名称:sync-engine,代码行数:20,代码来源:gmail.py

示例4: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, address, port, timeout, buffer_size=PAGESIZE,
                 lock_class=Semaphore):
        self.address = address
        self.port = port
        self.timeout = timeout

        self.buffer = b''
        self.buffer_size = buffer_size

        self.socket = None
        self.lock = lock_class() 
开发者ID:wtolson,项目名称:gnsq,代码行数:13,代码来源:stream.py

示例5: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, ws, lag_tolerance_secs=0.1):
        self.ws = ws
        self.lag_tolerance_secs = lag_tolerance_secs

        # This lock is used to make sure that multiple greenlets
        # cannot send to the same socket concurrently.
        self.send_lock = Semaphore() 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:9,代码来源:sockets.py

示例6: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, *args, **kwargs):
        BaseServer.__init__(self, *args, **kwargs)
        from gevent.lock import Semaphore
        self._writelock = Semaphore() 
开发者ID:leancloud,项目名称:satori,代码行数:6,代码来源:server.py

示例7: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, fobj, *args, **kwargs):
        """
        :param fobj: The underlying file-like object to wrap, or an integer fileno
           that will be pass to :func:`os.fdopen` along with everything in *args*.
        :keyword bool lock: If True (the default) then all operations will
           be performed one-by-one. Note that this does not guarantee that, if using
           this file object from multiple threads/greenlets, operations will be performed
           in any particular order, only that no two operations will be attempted at the
           same time. You can also pass your own :class:`gevent.lock.Semaphore` to synchronize
           file operations with an external resource.
        :keyword bool close: If True (the default) then when this object is closed,
           the underlying object is closed as well.
        """
        self._close = kwargs.pop('close', True)
        self.threadpool = kwargs.pop('threadpool', None)
        self.lock = kwargs.pop('lock', True)
        if kwargs:
            raise TypeError('Unexpected arguments: %r' % kwargs.keys())
        if self.lock is True:
            self.lock = Semaphore()
        elif not self.lock:
            self.lock = DummySemaphore()
        if not hasattr(self.lock, '__enter__'):
            raise TypeError('Expected a Semaphore or boolean, got %r' % type(self.lock))
        if isinstance(fobj, integer_types):
            if not self._close:
                # we cannot do this, since fdopen object will close the descriptor
                raise TypeError('FileObjectThread does not support close=False')
            fobj = os.fdopen(fobj, *args)
        self.io = fobj
        if self.threadpool is None:
            self.threadpool = get_hub().threadpool 
开发者ID:leancloud,项目名称:satori,代码行数:34,代码来源:fileobject.py

示例8: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, size=None, greenlet_class=None):
        """
        Create a new pool.

        A pool is like a group, but the maximum number of members
        is governed by the *size* parameter.

        :keyword int size: If given, this non-negative integer is the
            maximum count of active greenlets that will be allowed in
            this pool. A few values have special significance:

            * ``None`` (the default) places no limit on the number of
              greenlets. This is useful when you need to track, but not limit,
              greenlets, as with :class:`gevent.pywsgi.WSGIServer`. A :class:`Group`
              may be a more efficient way to achieve the same effect.
            * ``0`` creates a pool that can never have any active greenlets. Attempting
              to spawn in this pool will block forever. This is only useful
              if an application uses :meth:`wait_available` with a timeout and checks
              :meth:`free_count` before attempting to spawn.
        """
        if size is not None and size < 0:
            raise ValueError('size must not be negative: %r' % (size, ))
        Group.__init__(self)
        self.size = size
        if greenlet_class is not None:
            self.greenlet_class = greenlet_class
        if size is None:
            self._semaphore = DummySemaphore()
        else:
            self._semaphore = Semaphore(size) 
开发者ID:leancloud,项目名称:satori,代码行数:32,代码来源:pool.py

示例9: _init

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def _init(self, maxsize):
        self._size = 0
        self._semaphore = Semaphore(1)
        self._lock = Lock()
        self.task_queue = Queue()
        self._set_maxsize(maxsize) 
开发者ID:leancloud,项目名称:satori,代码行数:8,代码来源:threadpool.py

示例10: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, listener, profiler=None, interval=INTERVAL,
                 log=LOG, pickle_protocol=PICKLE_PROTOCOL, **server_kwargs):
        StreamServer.__init__(self, listener, **server_kwargs)
        ProfilingServer.__init__(self, profiler, interval,
                                 log, pickle_protocol)
        self.lock = Semaphore()
        self.profiling_greenlet = None 
开发者ID:what-studio,项目名称:profiling,代码行数:9,代码来源:gevent.py

示例11: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, parent, io_loop=None):
        self._parent = parent
        self._closing = False
        self._user_queries = {}
        self._cursor_cache = {}

        self._write_mutex = Semaphore()
        self._socket = None 
开发者ID:rethinkdb,项目名称:rethinkdb-python,代码行数:10,代码来源:net_gevent.py

示例12: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, huskar_client, startup_max_concurrency=None):
        self.base_path = huskar_client.base_path
        self.client = huskar_client.client
        self.tree_map = {}
        self.tree_holder_class = TreeHolder
        self.tree_watcher_class = TreeWatcher
        self.lock = Semaphore()
        if startup_max_concurrency:
            self.throttle = Semaphore(startup_max_concurrency)
        else:
            self.throttle = None 
开发者ID:huskar-org,项目名称:huskar,代码行数:13,代码来源:hub.py

示例13: _new_gevent_lock

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def _new_gevent_lock(*args, **kwargs):
    from gevent.lock import Semaphore
    return Semaphore(*args, **kwargs) 
开发者ID:seprich,项目名称:py-bson-rpc,代码行数:5,代码来源:concurrent.py

示例14: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, name, task):
        self.name = name
        self.task = task
        self.lock = Semaphore(task.max_concurrent) 
开发者ID:b1naryth1ef,项目名称:rowboat,代码行数:6,代码来源:__init__.py

示例15: __init__

# 需要导入模块: from gevent import lock [as 别名]
# 或者: from gevent.lock import Semaphore [as 别名]
def __init__(self, rdb, key_name):
        self.rdb = rdb
        self.key_name = key_name
        self.update_key_name = u'redis-set:{}'.format(self.key_name)

        self._set = rdb.smembers(key_name)
        self._lock = Semaphore()
        self._ps = self.rdb.pubsub()
        self._ps.subscribe(self.update_key_name)

        self._inst = gevent.spawn(self._listener) 
开发者ID:b1naryth1ef,项目名称:rowboat,代码行数:13,代码来源:redis.py


注:本文中的gevent.lock.Semaphore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。