Exemplo n.º 1
0
 def test_assignment(self):
     my_local = corolocal.local()
     my_local.a = 1
     def do_something():
         my_local.b = 2
         self.assertEqual(my_local.b, 2)
         try:
             my_local.a
             self.fail()
         except AttributeError:
             pass
     eventlet.spawn(do_something).wait()
     self.assertEqual(my_local.a, 1)
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     super(ContextStackManagerEventletMixin, self).__init__(*args, **kwargs)
     try:
         from eventlet.corolocal import local
         from eventlet.semaphore import BoundedSemaphore
     except ImportError:
         raise RuntimeError(
             'the eventlet library is required for %s' %
             self.__class__.__name__
         )
     self._coroutine_context = local()
     self._contexts.append(self._coroutine_context)
     self._coroutine_lock = BoundedSemaphore()
Exemplo n.º 3
0
    def test_no_leaking(self):
        refs = weakref.WeakKeyDictionary()
        my_local = corolocal.local()
        class X(object):
            pass
        def do_something(i):
            o = X()
            refs[o] = True
            my_local.foo = o

        p = eventlet.GreenPool()
        for i in six.moves.range(100):
            p.spawn(do_something, i)
        p.waitall()
        del p
        # at this point all our coros have terminated
        self.assertEqual(len(refs), 1)
Exemplo n.º 4
0
# limitations under the License. See accompanying LICENSE file.

import config

import random
import sys
import time
from eventlet import corolocal
from collections import namedtuple
import socket
import pickle
import base64
import logging
import webob.dec

span_stack = corolocal.local()

Span = namedtuple('Span', 'trace_id parent_id id name notes')
Note = namedtuple('Note', 'time value service_name address port')

def start(service_name, name, address, port, trace_info=None):
    parent_id = None
    if hasattr(span_stack, 'trace_id'):
        trace_id = span_stack.trace_id
        parent_id = span_stack.spans[-1].id
    else:
        if trace_info is None:
            trace_id = span_stack.trace_id = getId()
        else:
            trace_id = span_stack.trace_id = trace_info[0]
            parent_id = trace_info[1]
Exemplo n.º 5
0
import redis
import uuid
from django.conf import settings
from django.core.signals import request_finished
import datetime

try:
    from eventlet.corolocal import local
except ImportError:
    from threading import local

REDIS_HOST = getattr(settings, 'REDIS_HOST', '127.0.0.1')
REDIS_PORT = getattr(settings, 'REDIS_PORT', 6379)
REDIS_DB = getattr(settings, 'REDIS_DB', 8)
REDIS_LOCAL = local()


def _get_redis():
    try:
        return REDIS_LOCAL.client
    except AttributeError:
        client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)
        REDIS_LOCAL.client = client
        return client

def cleanup(sender, **kwargs):
    try:
        client = REDIS_LOCAL.client
        del REDIS_LOCAL.client
    except AttributeError:
 def __call__(self, env, start_response):
     # preserve user token for later forwarding to contrail API server
     cur_greenlet = getcurrent()
     cur_greenlet.contrail_vars = corolocal.local()
     cur_greenlet.contrail_vars.token = env.get('HTTP_X_AUTH_TOKEN')
     return self._app(env, start_response)
Exemplo n.º 7
0
from eventlet.event import Event
from eventlet.semaphore import Semaphore

from dtest import capture
from dtest.constants import *
from dtest.exceptions import DTestException
from dtest import resource
from dtest import test


# Default line width
DEF_LINEWIDTH = 78


# Current output for issuing status messages
_output = local()


class _DTestStatus(object):
    """
    _DTestStatus
    ============

    The _DTestStatus class is a stream look-alike class, an instance
    of which implements the special ``dtest.status`` stream.  Data
    written to the stream will be passed to the status() method of the
    current DTestOutput object.  Thread-local data is used to store
    the current DTestOutput object, so multiple output objects may be
    safely used simultaneously.
    """