當前位置: 首頁>>代碼示例>>Python>>正文


Python gevent.Greenlet方法代碼示例

本文整理匯總了Python中gevent.Greenlet方法的典型用法代碼示例。如果您正苦於以下問題:Python gevent.Greenlet方法的具體用法?Python gevent.Greenlet怎麽用?Python gevent.Greenlet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gevent的用法示例。


在下文中一共展示了gevent.Greenlet方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: spawn_greenlet

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def spawn_greenlet(self, func, args, kwargs, greenlet_name):
    """Returns a gevent.Greenlet which has been initialized with the correct
    greenlet-local-storage state.

    Args:
      * greenlet_name (str|None) - If non-None, assign this to the greenlet's
        name.
    """
    self.close_non_parent_step()

    to_run = [pgs._get_setter_on_spawn() for pgs in PerGreentletStateRegistry]

    current_step = self._step_stack[-1]
    def _runner():
      for fn in to_run:
        fn()
      try:
        return func(*args, **kwargs)
      finally:
        self.close_non_parent_step()
    ret = gevent.spawn(_runner)
    if greenlet_name is not None:
      ret.name = greenlet_name
    current_step.greenlets.append(ret)
    return ret 
開發者ID:luci,項目名稱:recipes-py,代碼行數:27,代碼來源:engine.py

示例2: spawn_immediate

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def spawn_immediate(self, func, *args, **kwargs):
    """Returns a Future to the concurrently running `func(*args, **kwargs)`.

    This is like `spawn`, except that it IMMEDIATELY switches to the new
    Greenlet. You may want to use this if you want to e.g. launch a background
    step and then another step which waits for the daemon.

    Kwargs:

      * __name (str) - If provided, will assign this name to the spawned
        greenlet. Useful if this greenlet ends up raising an exception, this
        name will appear in the stderr logging for the engine. See
        `Future.name` for more information.
      * __meta (any) - If provided, will assign this metadata to the returned
        Future. This field is for your exclusive use.
      * Everything else is passed to `func`.

    Returns a Future of `func`'s result.
    """
    name = kwargs.pop('__name', None)
    meta = kwargs.pop('__meta', None)
    chan = self.make_channel()
    def _immediate_runner():
      chan.get()
      return func(*args, **kwargs)
    ret = self.spawn(_immediate_runner, __name=name, __meta=meta)
    chan.put(None)  # Pass execution to _immediate_runner
    return ret 
開發者ID:luci,項目名稱:recipes-py,代碼行數:30,代碼來源:api.py

示例3: join_routines

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def join_routines(routines):
    greenlets = [_ for _ in routines if isinstance(_, gevent.Greenlet)]
    if enabled:
        gevent.joinall(greenlets) 
開發者ID:mitre,項目名稱:cascade-server,代碼行數:6,代碼來源:async.py

示例4: _on_child_hook

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def _on_child_hook():
    # This is called in the hub greenlet. To let the function
    # do more useful work, like use blocking functions,
    # we run it in a new greenlet; see gevent.hub.signal
    if callable(_child_handler):
        # None is a valid value for the frame argument
        from gevent import Greenlet
        greenlet = Greenlet(_child_handler, _signal.SIGCHLD, None)
        greenlet.switch() 
開發者ID:leancloud,項目名稱:satori,代碼行數:11,代碼來源:signal.py

示例5: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def __init__(self,
                 zmq_context,
                 zmq_proxy_xsub_url=ait.SERVER_DEFAULT_XSUB_URL,
                 zmq_proxy_xpub_url=ait.SERVER_DEFAULT_XPUB_URL,
                 **kwargs):

        self.context = zmq_context
        # open PUB socket & connect to broker
        self.pub = self.context.socket(zmq.PUB)
        self.pub.connect(zmq_proxy_xsub_url.replace('*', 'localhost'))

        # calls gevent.Greenlet or gs.DatagramServer __init__
        super(ZMQClient, self).__init__(**kwargs) 
開發者ID:NASA-AMMOS,項目名稱:AIT-Core,代碼行數:15,代碼來源:client.py

示例6: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def __init__(self):
        self.context = zmq.Context()
        self.XSUB_URL = ait.config.get('server.xsub',
                                        ait.SERVER_DEFAULT_XSUB_URL)
        self.XPUB_URL = ait.config.get('server.xpub',
                                        ait.SERVER_DEFAULT_XPUB_URL)

        ## Name of the topic associated with external commands
        self.command_topic = ait.config.get('command.topic',
                                        ait.DEFAULT_CMD_TOPIC)

        gevent.Greenlet.__init__(self) 
開發者ID:NASA-AMMOS,項目名稱:AIT-Core,代碼行數:14,代碼來源:broker.py

示例7: _async_incoming_msg_handler

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def _async_incoming_msg_handler(self, transport_session, message, exception_handler):
        greenlet = Greenlet(
            self._incoming_msg_handler,
            transport_session,
            message,
        )
        greenlet.link_exception(exception_handler)
        self._msg_handler_pool.start(
            greenlet,
            blocking=True
        ) 
開發者ID:OpenSight,項目名稱:janus-cloud,代碼行數:13,代碼來源:ws.py

示例8: _spawn_greenlet

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def _spawn_greenlet(fn, *args, **kwargs):
    from gevent import Greenlet
    g = Greenlet(fn, *args, **kwargs)
    g.start()
    return g 
開發者ID:seprich,項目名稱:py-bson-rpc,代碼行數:7,代碼來源:concurrent.py

示例9: _get_running_greenlets

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def _get_running_greenlets():
    return [
        obj
        for obj in gc.get_objects()
        if isinstance(obj, gevent.Greenlet) and obj and not obj.dead
    ] 
開發者ID:raiden-network,項目名稱:raiden-services,代碼行數:8,代碼來源:conftest.py

示例10: start_publish_loop

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def start_publish_loop(self, publish_channel, publish_message):
        self.publish_channel = publish_channel
        self.publish_message = publish_message
        self.loop_greenlet = gevent.Greenlet(self._publish_loop)
        self.loop_greenlet.start() 
開發者ID:SalesforceFoundation,項目名稱:salesforce-streaming-client,代碼行數:7,代碼來源:test_it.py

示例11: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def __init__(self):
        self.event_queue = event_queue.EventQueue(DEFERRED_ACCOUNT_MIGRATION_EVENT_QUEUE)
        self.redis = self.event_queue.redis
        gevent.Greenlet.__init__(self) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:6,代碼來源:deferred_migration.py

示例12: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def __init__(self, syncback_id, process_number, total_processes, poll_interval=1,
                 retry_interval=30, num_workers=NUM_PARALLEL_ACCOUNTS,
                 batch_size=10):
        self.process_number = process_number
        self.total_processes = total_processes
        self.poll_interval = poll_interval
        self.retry_interval = retry_interval
        self.batch_size = batch_size
        self.keep_running = True
        self.workers = gevent.pool.Group()
        # Dictionary account_id -> semaphore to serialize action syncback for
        # any particular account.
        # TODO(emfree): We really only need to serialize actions that operate
        # on any given object. But IMAP actions are already effectively
        # serialized by using an IMAP connection pool of size 1, so it doesn't
        # matter too much.
        self.account_semaphores = defaultdict(lambda: BoundedSemaphore(1))
        # This SyncbackService performs syncback for only and all the accounts
        # on shards it is reponsible for; shards are divided up between
        # running SyncbackServices.
        self.log = logger.new(component='syncback')
        syncback_assignments = config.get("SYNCBACK_ASSIGNMENTS", {})
        if syncback_id in syncback_assignments:
            self.keys = [key for key in engine_manager.engines
                         if key in syncback_assignments[syncback_id] and
                         key % total_processes == process_number]
        else:
            self.log.warn("No shards assigned to syncback server",
                          syncback_id=syncback_id)
            self.keys = []

        self.log = logger.new(component='syncback')
        self.num_workers = num_workers
        self.num_idle_workers = 0
        self.worker_did_finish = gevent.event.Event()
        self.worker_did_finish.clear()
        self.task_queue = Queue()
        self.running_action_ids = set()
        gevent.Greenlet.__init__(self) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:41,代碼來源:actions.py

示例13: __init__

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import Greenlet [as 別名]
def __init__(self, account_id, namespace_id, provider_name, uid_accessor,
                 message_ttl=DEFAULT_MESSAGE_TTL, thread_ttl=DEFAULT_THREAD_TTL):
        bind_context(self, 'deletehandler', account_id)
        self.account_id = account_id
        self.namespace_id = namespace_id
        self.provider_name = provider_name
        self.uids_for_message = uid_accessor
        self.log = log.new(account_id=account_id)
        self.message_ttl = datetime.timedelta(seconds=message_ttl)
        self.thread_ttl = datetime.timedelta(seconds=thread_ttl)
        gevent.Greenlet.__init__(self) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:13,代碼來源:gc.py


注:本文中的gevent.Greenlet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。