How to use the gevent.getcurrent function in gevent

To help you get started, we’ve selected a few gevent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gevent / gevent / src / greentest / test__greenlet.py View on Github external
def test_tree_locals(self):
        g = g2 = None
        def func():
            child = greenlet.Greenlet()
            self.assertIs(child.spawn_tree_locals, getcurrent().spawn_tree_locals)
            self.assertIs(child.spawning_greenlet(), getcurrent())
        g = greenlet.Greenlet(func)
        g2 = greenlet.Greenlet(func)
        # Creating those greenlets did not give the main greenlet
        # a locals dict.
        self.assertFalse(hasattr(getcurrent(), 'spawn_tree_locals'),
                         getcurrent())
        self.assertIsNot(g.spawn_tree_locals, g2.spawn_tree_locals)
        g.start()
        g.join()

        raw = gevent.spawn_raw(func)
        self.assertIsNotNone(raw.spawn_tree_locals)
        self.assertIsNot(raw.spawn_tree_locals, g.spawn_tree_locals)
        self.assertIs(raw.spawning_greenlet(), getcurrent())
        while not raw.dead:
            gevent.sleep(0.01)
github gevent / gevent / greentest / test__proc.py View on Github external
        y = proc.spawn(lambda : getcurrent().throw(ExpectedError('test_wait_error')))
        y.link(x)
github TurboGears / Ming / ming / async.py View on Github external
def socket(self):
        pid = os.getpid()

        if pid != self.pid:
            self.sock = None
            self.sockets = Queue()
            self.pid = pid

        if self.sock is not None:
            self.log.debug('Return existing socket to greenlet %s', gevent.getcurrent() )
            return self.sock
        gl = gevent.getcurrent()
        try:
            self.sock = self.sockets.get_nowait()
            self.log.debug('Checkout socket %s to greenlet %s',
                           self.sock, gl )
        except Empty:
            self.sock = self.socket_factory()
            self.log.debug('Create socket in greenlet %s', gl)
        self.sock.last_greenlet = gl
        return self.sock
github PermaData / rill / rill / fn.py View on Github external
def current_component_runner():
    """
    Get the active Component Runner

    Returns
    -------
    ``rill.engine.runner.ComponentRunner``
    """
    import gevent
    import rill.engine.runner
    greenlet = gevent.getcurrent()
    assert isinstance(greenlet, rill.engine.runner.ComponentRunner)
    return greenlet
github paypal / support / support / ll.py View on Github external
def log_debug3(self, *args, **kw):
        """Log only with -ddd"""

        log_msgs[self.caller_mod + "--" + args[0]] += 1
        if self.trace_mod or _log_level >= 3:
            import gevent  # for getcurrent
            try:
                msg = apply(args[0].format, tuple(args[1:]))
                print >> the_file, "%s %s D3 (%s):%s" % (datetime.now().strftime("%d/%H:%M:%S.%f"),
                                                         self.caller_mod, id(gevent.getcurrent()),
                                                         self.tag), msg
            except:
                log_failure(args[0])
github rik0 / pynetsym / pynetsym / util / concurrency.py View on Github external
def get(self):
        try:
            return [value.get() for value in self.seq]
        except Exception as e:
            import gevent
            print "xxx", gevent.getcurrent()
            raise e
github 0rpc / zerorpc-python / zerorpc / heartbeat.py View on Github external
def __init__(self, channel, freq=5, passive=False):
        self._closed = False
        self._channel = channel
        self._heartbeat_freq = freq
        self._input_queue = gevent.queue.Channel()
        self._remote_last_hb = None
        self._lost_remote = False
        self._recv_task = gevent.spawn(self._recver)
        self._heartbeat_task = None
        self._parent_coroutine = gevent.getcurrent()
        self._compat_v2 = None
        if not passive:
            self._start_heartbeat()
github SalesforceFoundation / python-bayeux / src / python_bayeux / __init__.py View on Github external
if not self.shutdown_called:
            self.shutdown_called = True

            self.stop_greenlets = True

            LOG.info('client id {0} is shutting down'.format(self.client_id))

            # disconnect() runs in the main greenlet, so we want to give the
            # others a chance to finish
            # If we have been called by a callback (that is, the client wants
            # to shut down itself), then we don't want to wait for the execute
            # greenlet to stop, because we'll deadlock.
            # This also means that subclasses should not change self.greenlets
            relevant_greenlets = \
                self.greenlets[:-1] \
                if gevent.getcurrent() == self.greenlets[-1] \
                else self.greenlets

            gevent.joinall(relevant_greenlets)
            self.disconnect()
            self.shutdown_completed = True
github erikkaplun / spinoff / geventreactor / __init__.py View on Github external
def waitForGreenlet(g):
    """Link greenlet completion to Deferred"""
    from twisted.internet import reactor
    assert reactor.greenlet == getcurrent(), "must invoke this in the reactor greenlet"
    d = defer.Deferred()

    def cb(g):
        try:
            d.callback(g.get())
        except:
            d.errback(failure.Failure())

    g.link(d)
    return d
github heikoheiko / pydevp2p / devp2p / peer.py View on Github external
def stop(self):
        log.debug('stopped', thread=gevent.getcurrent())
        for p in self.protocols.values():
            p.stop()
        self.peermanager.peers.remove(self)
        self.kill()