當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。