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


Python gevent.lock方法代码示例

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


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

示例1: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __init__(self):
        global _all_handles
        # Generate label of text/unicode type from three random bytes.
        self._id = codecs.encode(os.urandom(3), "hex_codec").decode("ascii")
        self._legit_pid = os.getpid()
        self._make_nonblocking()

        # Define lock for synchronizing access to this handle within the current
        # process. Note that a `gevent.lock.Semaphore` instance lives on the
        # heap of the current process and cannot be used to synchronize access
        # across multiple processes. That is, this lock is only meaningful in
        # the current process. This is especially important to consider when the
        # platform supports fork()ing.
        self._lock = gevent.lock.Semaphore(value=1)
        self._closed = False
        _all_handles.append(self) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:18,代码来源:gipc.py

示例2: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __init__(self, comm, store, config=None):
        if config is None:
            config = {}

        self._stop = gevent.event.Event()

        self.max_concurrency = config.get('max_concurrency', 10)
        self.redis_config = config.get('redis', {})
        self.store = store

        self.queries_lock = gevent.lock.BoundedSemaphore()
        self.queries = {}

        comm.request_rpc_server_channel(
            QUERY_QUEUE,
            self,
            allowed_methods=['query', 'kill_query']
        ) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:20,代码来源:queryprocessor.py

示例3: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __init__(self, app):
        self.config = app.config
        self.db = app.services.db
        assert self.db is not None
        super(ChainService, self).__init__(app)
        log.info('initializing chain')
        coinbase = app.services.accounts.coinbase
        self.chain = Chain(self.db, new_head_cb=self._on_new_head, coinbase=coinbase)
        log.info('chain at', number=self.chain.head.number)
        self.synchronizer = Synchronizer(self, force_sync=None)

        self.block_queue = Queue(maxsize=self.block_queue_size)
        self.transaction_queue = Queue(maxsize=self.transaction_queue_size)
        self.add_blocks_lock = False
        self.add_transaction_lock = gevent.lock.Semaphore()
        self.broadcast_filter = DuplicatesFilter()
        self.on_new_head_cbs = []
        self.on_new_head_candidate_cbs = [] 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:20,代码来源:eth_service.py

示例4: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __init__(self, url, recv_msg_cbk=None, close_cbk=None, protocols=None, msg_encoder=None, msg_decoder=None):
        # patch socket.sendall to protect it with lock,
        # in order to prevent sending data from multiple greenlets concurrently
        WebSocketClient.__init__(self, url, protocols=protocols)
        self._msg_encoder = msg_encoder or self.DEFAULT_ENCODER
        self._msg_decoder = msg_decoder or self.DEFAULT_DECODER
        lock = RLock()
        _sendall = self.sock.sendall
        self._recv_msg_cbk = recv_msg_cbk
        self._close_cbk = close_cbk

        def sendall(data):
            lock.acquire()
            try:
                _sendall(data)
            except Exception:
                raise
            finally:
                lock.release()
        self.sock.sendall = sendall

        self.connect()
        log.info('Created {0}'.format(self)) 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:25,代码来源:ws.py

示例5: run

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def run(self, job):
        lock = None
        if self.task.global_lock:
            lock = rdb.lock('{}:{}'.format(
                self.task.name,
                self.task.global_lock(
                    *job['args'],
                    **job['kwargs']
                )
            ))
            lock.acquire()

        if self.task.max_concurrent:
            self.lock.acquire()

        self.process(job)

        if lock:
            lock.release()

        if self.task.max_concurrent:
            self.lock.release() 
开发者ID:b1naryth1ef,项目名称:rowboat,代码行数:24,代码来源:__init__.py

示例6: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __init__(self):
        self.alarms = {}
        self.lock = RLock() 
开发者ID:leancloud,项目名称:satori,代码行数:5,代码来源:main.py

示例7: __getstate__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __getstate__(self):
        # Hook into the pickling process. The default state which is pickled is
        # self.__dict__. Remove the lock from it. The general motivation is:
        # conceptually, the lock's state becomes meaningless in the moment the
        # handle is pickled around. The specific motivation is:
        # `gevent.lock.Semaphore` is not picklable with some versions of gevent
        # on Windows, see https://github.com/jgehrcke/gipc/issues/36. Hence, do
        # not even try to pickle it to the child process.
        state = self.__dict__.copy()
        del state['_lock']
        return state 
开发者ID:jgehrcke,项目名称:gipc,代码行数:13,代码来源:gipc.py

示例8: __setstate__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __setstate__(self, state):
        # Restore instance attributes.
        self.__dict__.update(state)

        # Create a fresh lock for synchronizing the access to this handle in the
        # current process.
        self._lock = gevent.lock.Semaphore(value=1) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:9,代码来源:gipc.py

示例9: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [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

示例10: send

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def send(self, data):
        self.ensure_connection()

        with self.lock:
            try:
                return self.socket.sendall(data)
            except socket.error as error:
                six.raise_from(NSQSocketError(*error.args), error) 
开发者ID:wtolson,项目名称:gnsq,代码行数:10,代码来源:stream.py

示例11: init_app

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def init_app(app):
    global PREVENT_WRITE
    global PREVENT_WRITE_GUARD

    app.config['REMEMBER_COOKIE_NAME'] = None  # to block remember cookie
    LOGIN_MANAGER.init_app(app)

    # initialize PREVENT_WRITE
    PREVENT_WRITE_GUARD = gevent.lock.BoundedSemaphore()
    PREVENT_WRITE = None 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:12,代码来源:aaa.py

示例12: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def __init__(self):
        self.num_readers = 0
        self.num_writers = 0

        self.m1 = gevent.lock.Semaphore(1)
        self.m2 = gevent.lock.Semaphore(1)
        self.m3 = gevent.lock.Semaphore(1)
        self.w = gevent.lock.Semaphore(1)
        self.r = gevent.lock.Semaphore(1) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:11,代码来源:utils.py

示例13: lock

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def lock(self):
        self.m2.acquire()

        self.num_writers += 1
        if self.num_writers == 1:
            self.r.acquire()

        self.m2.release()
        self.w.acquire() 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:11,代码来源:utils.py

示例14: add_block

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [as 别名]
def add_block(self, t_block, proto):
        "adds a block to the block_queue and spawns _add_block if not running"
        self.block_queue.put((t_block, proto))  # blocks if full
        if not self.add_blocks_lock:
            self.add_blocks_lock = True  # need to lock here (ctx switch is later)
            gevent.spawn(self._add_blocks) 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:8,代码来源:eth_service.py

示例15: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import lock [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


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