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


Python gevent.event方法代码示例

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


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

示例1: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def __init__(self, name, chassis, config):
        self.table = None
        self.agg_table = None

        self._actor_queue = gevent.queue.Queue(maxsize=128)
        self._actor_glet = None
        self._actor_commands_ts = collections.defaultdict(int)
        self._poll_glet = None
        self._age_out_glet = None
        self._emit_counter = 0

        self.last_run = None
        self.last_successful_run = None
        self.last_ageout_run = None
        self._sub_state = None
        self._sub_state_message = None

        self.poll_event = gevent.event.Event()

        self.state_lock = RWLock()

        super(BasePollerFT, self).__init__(name, chassis, config) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:24,代码来源:basepoller.py

示例2: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [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 event [as 别名]
def __init__(self, comm, store, topic, config):
        self._stop = gevent.event.Event()
        self._low_disk = gevent.event.Event()

        self.store = store
        self.comm = comm
        self.comm.request_sub_channel(
            topic,
            self,
            allowed_methods=['log'],
            name='mbus:log:writer',
            multi_write=True
        )

        self._disk_monitor_glet = DiskSpaceMonitor(
            threshold=config.get('threshold', 70),
            low_disk=self._low_disk
        )
        self._disk_monitor_glet.start() 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:21,代码来源:writer.py

示例4: enable

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def enable(self, app=None):
        """Enable event loop integration with gevent.
        Parameters
        ----------
        app : ignored
            Ignored, it's only a placeholder to keep the call signature of all
            gui activation methods consistent, which simplifies the logic of
            supporting magics.
        Notes
        -----
        This methods sets the PyOS_InputHook for gevent, which allows
        gevent greenlets to run in the background while interactively using
        IPython.
        """
        self.manager.set_inputhook(inputhook_gevent)
        self._current_gui = GUI_GEVENT
        return app 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:19,代码来源:console_service.py

示例5: __init__

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def __init__(self, iterable=None, maxlen=None):
        """Returns a new GeventDeque object initialized left-to-right
        (using append()) with data from *iterable*. If *iterable* is
        not specified, the new GeventDeque is empty.

        If *maxlen* is not specified or is ``None``, GeventDeques may
        grow to an arbitrary length.  Otherwise, the GeventDeque is
        bounded to the specified maximum length.  Once a bounded
        length GeventDeque is full, when new items are added, a
        corresponding number of items are discarded from the opposite
        end.
        """
        if iterable is None:
            self._deque = collections.deque(maxlen=maxlen)
        else:
            self._deque = collections.deque(iterable, maxlen)

        self.notEmpty = gevent.event.Event()

        if len(self._deque) > 0:
            self.notEmpty.set() 
开发者ID:NASA-AMMOS,项目名称:AIT-Core,代码行数:23,代码来源:api.py

示例6: _recv_msg_cbk

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def _recv_msg_cbk(self, msg):
        try:
            if 'transaction' in msg:
                transaction = self._transactions.get(msg['transaction'], None)
                if transaction:
                    transaction.response = msg
            elif msg['janus'] == 'timeout':
                log.debug('Receive session timeout from Janus server: {}'.format(self.url))
                self.destroy()
            elif msg['janus'] == 'detached':
                log.debug('Receive async event {} from Janus server: {}'.format(msg, self.url))
                handle = self._handles.pop(msg['sender'], None)
                if handle:
                    handle.on_close()
            elif 'sender' in msg:
                log.debug('Receive async event {} from Janus server: {}'.format(msg, self.url))
                handle = self._handles.get(msg['sender'], None)
                if handle:
                    handle.on_async_event(msg)
            else:
                log.warn('Receive a invalid message {} on session {} for server {}'.format(msg, self.session_id, self.url))
        except Exception:
            log.exception('Received a malformat msg {}'.format(msg)) 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:25,代码来源:backend_session.py

示例7: send

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def send(self, signal=dispatcher.Any, sender=dispatcher.Anonymous,
             *args, **kwargs):
        """
        Send signal/event to registered receivers.

        :param args:
        :param kwargs:
        :return:
        """
        if signal is None:
            signal = dispatcher.Any
        if sender is None:
            sender = dispatcher.Anonymous

        self._dispatcher.send(signal, sender, *args, **kwargs)

        # dispatch this signal to the shell.

        logger.info("sending signal: %s", signal)

        if self._outbox:
            self._outbox.put_nowait((signal, kwargs)) 
开发者ID:eavatar,项目名称:eavatar-me,代码行数:24,代码来源:agent.py

示例8: _mark_action_as_failed

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def _mark_action_as_failed(self, action_log_entry, db_session):
        self.log.critical('Max retries reached, giving up.', exc_info=True)
        action_log_entry.status = 'failed'
        self._log_to_statsd(action_log_entry.status)

        if action_log_entry.action == 'create_event':
            # Creating a remote copy of the event failed.
            # Without it, none of the other pending actions
            # for this event will succeed. To prevent their
            # execution, preemptively mark them as failed.
            actions = db_session.query(ActionLog).filter_by(
                        record_id=action_log_entry.record_id,
                        namespace_id=action_log_entry.namespace_id,
                        status='pending').all()
            for pending_action in actions:
                pending_action.status = 'failed'

            # Mark the local copy as deleted so future actions can't be made.
            event = db_session.query(Event).get(action_log_entry.record_id)
            event.deleted_at = datetime.now()
        db_session.commit() 
开发者ID:nylas,项目名称:sync-engine,代码行数:23,代码来源:actions.py

示例9: start

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def start(self):
            # Start grabbing SIGCHLD within libev event loop.
            gevent.get_hub().loop.install_sigchld()
            # Run new process (based on `fork()` on POSIX-compliant systems).
            super(_GProcess, self).start()
            # The occurrence of SIGCHLD is recorded asynchronously in libev.
            # This guarantees proper behavior even if the child watcher is
            # started after the child exits. Start child watcher now.
            self._sigchld_watcher = gevent.get_hub().loop.child(self.pid)
            self._returnevent = gevent.event.Event()
            self._sigchld_watcher.start(
                self._on_sigchld, self._sigchld_watcher)
            log.debug("SIGCHLD watcher for %s started.", self.pid) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:15,代码来源:gipc.py

示例10: _on_sigchld

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def _on_sigchld(self, watcher):
            """Callback of libev child watcher. Called when libev event loop
            catches corresponding SIGCHLD signal.
            """
            watcher.stop()
            # Status evaluation copied from `multiprocessing.forking` in Py2.7.
            if os.WIFSIGNALED(watcher.rstatus):
                self._popen.returncode = -os.WTERMSIG(watcher.rstatus)
            else:
                assert os.WIFEXITED(watcher.rstatus)
                self._popen.returncode = os.WEXITSTATUS(watcher.rstatus)
            self._returnevent.set()
            log.debug("SIGCHLD watcher callback for %s invoked. Exitcode "
                      "stored: %s", self.pid, self._popen.returncode) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:16,代码来源:gipc.py

示例11: get

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def get(self, timeout=None):
        """Receive, decode and return data from the pipe. Block
        gevent-cooperatively until data is available or timeout expires. The
        default decoder is ``pickle.loads``.

        :arg timeout: ``None`` (default) or a ``gevent.Timeout``
            instance. The timeout must be started to take effect and is
            canceled when the first byte of a new message arrives (i.e.
            providing a timeout does not guarantee that the method completes
            within the timeout interval).

        :returns: a Python object.

        Raises:
            - :exc:`gevent.Timeout` (if provided)
            - :exc:`GIPCError`
            - :exc:`GIPCClosed`
            - :exc:`pickle.UnpicklingError`

        Recommended usage for silent timeout control::

            with gevent.Timeout(TIME_SECONDS, False) as t:
                reader.get(timeout=t)

        .. warning::

            The timeout control is currently not available on Windows,
            because Windows can't apply select() to pipe handles.
            An ``OSError`` is expected to be raised in case you set a
            timeout.
        """
        self._validate()
        with self._lock:
            if timeout:
                # Wait for ready-to-read event.
                h = gevent.get_hub()
                h.wait(h.loop.io(self._fd, 1))
                timeout.cancel()
            msize, = struct.unpack("!i", self._recv_in_buffer(4).getvalue())
            bindata = self._recv_in_buffer(msize).getvalue()
        return self._decoder(bindata) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:43,代码来源:gipc.py

示例12: publish

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def publish(self, topic, data, defer=None, block=True, timeout=None,
                raise_error=True):
        """Publish a message to the given topic.

        :param topic: the topic to publish to

        :param data: bytestring data to publish

        :param defer: duration in milliseconds to defer before publishing
            (requires nsq 0.3.6)

        :param block: wait for a connection to become available before
            publishing the message. If block is `False` and no connections
            are available, :class:`~gnsq.errors.NSQNoConnections` is raised

        :param timeout: if timeout is a positive number, it blocks at most
            ``timeout`` seconds before raising
            :class:`~gnsq.errors.NSQNoConnections`

        :param raise_error: if ``True``, it blocks until a response is received
            from the nsqd server, and any error response is raised. Otherwise
            an :class:`~gevent.event.AsyncResult` is returned
        """
        result = AsyncResult()
        conn = self._get_connection(block=block, timeout=timeout)

        try:
            self._response_queues[conn].append(result)
            conn.publish(topic, data, defer=defer)
        finally:
            self._put_connection(conn)

        if raise_error:
            return result.get()

        return result 
开发者ID:wtolson,项目名称:gnsq,代码行数:38,代码来源:producer.py

示例13: multipublish

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def multipublish(self, topic, messages, block=True, timeout=None,
                     raise_error=True):
        """Publish an iterable of messages to the given topic.

        :param topic: the topic to publish to

        :param messages: iterable of bytestrings to publish

        :param block: wait for a connection to become available before
            publishing the message. If block is `False` and no connections
            are available, :class:`~gnsq.errors.NSQNoConnections` is raised

        :param timeout: if timeout is a positive number, it blocks at most
            ``timeout`` seconds before raising
            :class:`~gnsq.errors.NSQNoConnections`

        :param raise_error: if ``True``, it blocks until a response is received
            from the nsqd server, and any error response is raised. Otherwise
            an :class:`~gevent.event.AsyncResult` is returned
        """
        result = AsyncResult()
        conn = self._get_connection(block=block, timeout=timeout)

        try:
            self._response_queues[conn].append(result)
            conn.multipublish(topic, messages)
        finally:
            self._put_connection(conn)

        if raise_error:
            return result.get()

        return result 
开发者ID:wtolson,项目名称:gnsq,代码行数:35,代码来源:producer.py

示例14: run

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def run(self):
        while True:
            LOG.debug('RPC Fanout reply recving from {}:reply'.format(self.fanout))
            body = self.reply_socket.recv_json()
            LOG.debug('RPC Fanout reply from {}:reply recvd: {!r}'.format(self.fanout, body))
            self.reply_socket.send('OK')
            LOG.debug('RPC Fanout reply from {}:reply recvd: {!r} - ok'.format(self.fanout, body))

            source = body.get('source', None)
            if source is None:
                LOG.error('No source in reply in ZMQRpcFanoutClientChannel {}'.format(self.fanout))
                continue

            id_ = body.get('id', None)
            if id_ is None:
                LOG.error('No id in reply in ZMQRpcFanoutClientChannel {} from {}'.format(self.fanout, source))
                continue
            actreq = self.active_rpcs.get(id_, None)
            if actreq is None:
                LOG.error('Unknown id {} in reply in ZMQRpcFanoutClientChannel {} from {}'.format(id_, self.fanout, source))
                continue

            result = body.get('result', None)
            if result is None:
                actreq['errors'] += 1
                errmsg = body.get('error', 'no error in reply')
                LOG.error('Error in RPC reply from {}: {}'.format(source, errmsg))

            else:
                actreq['answers'][source] = result
            LOG.debug('RPC Fanout state: {!r}'.format(actreq))

            if len(actreq['answers'])+actreq['errors'] >= actreq['num_results']:
                actreq['event'].set({
                    'answers': actreq['answers'],
                    'errors': actreq['errors']
                })
                self.active_rpcs.pop(id_)

            gevent.sleep(0) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:42,代码来源:zmqredis.py

示例15: _send_cmd

# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import event [as 别名]
def _send_cmd(self, command, to_slaves=True, params=None, and_discard=False):
        """Sends command to slaves or chassis over mgmt bus.

        Args:
            command (str): command
            params (dict): params of the command
            and_discard (bool): discard answer, don't wait
            to_slaves (bool): send command to nodes, otherwise to chassis

        Returns:
            returns a gevent.event.AsyncResult that is signaled
            when all the answers are collected
        """
        if params is None:
            params = {}

        rpc_client = self._slaves_rpc_client
        num_results = len(self.ftlist)
        if not to_slaves:
            rpc_client = self._chassis_rpc_client
            num_results = self.num_chassis

        return rpc_client.send_rpc(
            command,
            params=params,
            and_discard=and_discard,
            num_results=num_results
        ) 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:30,代码来源:mgmtbus.py


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