Python eventlet.getcurrent() Examples

The following are 5 code examples of eventlet.getcurrent(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module eventlet , or try the search function .
Example #1
Source File: executor.py    From forge with Apache License 2.0 5 votes vote down vote up
def wait(self):
        if self.value is PENDING:
            if self.thread not in (None, eventlet.getcurrent()):
                self.thread.wait()
        for ch in self.children:
            ch.wait()
        if self.child_errors > 0 and self.value is not ERROR:
            errors = [e for e in self.leaf_errors if not e._recovered]
            if errors:
                self.value = ERROR
                self.exception = (ChildError, ChildError(self, self.leaf_errors), None) 
Example #2
Source File: base_consumer.py    From distributed_framework with Apache License 2.0 5 votes vote down vote up
def get_concurrent_info(cls):
        concurrent_info = ''
        if cls.global_concurrent_mode == 1:
            concurrent_info = f'[{threading.current_thread()}  {threading.active_count()}]'
        elif cls.global_concurrent_mode == 2:
            concurrent_info = f'[{gevent.getcurrent()}  {threading.active_count()}]'
        elif cls.global_concurrent_mode == 3:
            # noinspection PyArgumentList
            concurrent_info = f'[{eventlet.getcurrent()}  {threading.active_count()}]'
        return concurrent_info 
Example #3
Source File: _utils.py    From os-win with Apache License 2.0 5 votes vote down vote up
def avoid_blocking_call(f, *args, **kwargs):
    """Ensures that the invoked method will not block other greenthreads.

    Performs the call in a different thread using tpool.execute when called
    from a greenthread.
    """
    # Note that eventlet.getcurrent will always return a greenlet object.
    # In case of a greenthread, the parent greenlet will always be the hub
    # loop greenlet.
    if eventlet.getcurrent().parent:
        return tpool.execute(f, *args, **kwargs)
    else:
        return f(*args, **kwargs) 
Example #4
Source File: actor.py    From mochi with MIT License 5 votes vote down vote up
def run(self, *args, **kwargs):
        greenlet_id = id(eventlet.getcurrent())
        _actor_map[greenlet_id] = self
        try:
            self._callback(*args, **kwargs)
        finally:
            if greenlet_id in _actor_map.keys():
                del _actor_map[greenlet_id] 
Example #5
Source File: actor.py    From mochi with MIT License 5 votes vote down vote up
def self():
    cur_green = eventlet.getcurrent()
    return _actor_map.get(id(cur_green))