def test_pool_smash(self):
        # The premise is that a coroutine in a Pool tries to get a token out
        # of a token pool but times out before getting the token.  We verify
        # that neither pool is adversely affected by this situation.
        from eventlet import pools
        pool = self.klass(min_size=1, max_size=1)
        tp = pools.TokenPool(max_size=1)
        token = tp.get()  # empty pool
        def do_receive(tp):
            api.exc_after(0, RuntimeError())
            try:
                t = tp.get()
                self.fail("Shouldn't have recieved anything from the pool")
            except RuntimeError:
                return 'timed out'

        # the execute makes the token pool expect that coroutine, but then
        # immediately cuts bait
        e1 = pool.execute(do_receive, tp)
        self.assertEquals(e1.wait(), 'timed out')

        # the pool can get some random item back
        def send_wakeup(tp):
            tp.put('wakeup')
        api.spawn(send_wakeup, tp)

        # now we ask the pool to run something else, which should not
        # be affected by the previous send at all
        def resume():
            return 'resumed'
        e2 = pool.execute(resume)
        self.assertEquals(e2.wait(), 'resumed')

        # we should be able to get out the thing we put in there, too
        self.assertEquals(tp.get(), 'wakeup')
Exemple #2
0
 def __init__(self, sock, origin, protocol, path):
     self.sock = sock
     self.origin = origin
     self.protocol = protocol
     self.path = path
     self._buf = ""
     self._msgs = collections.deque()
     self._sendlock = pools.TokenPool(1)
Exemple #3
0
 def __init__(self, instr, outstr, dead_list=None):
     """
     :param instr: a file-like object which supports ``read()``.
     :param outstr: a file-like object which supports ``write()`` and
         ``flush()``.
     :param dead_list: a list of ids of remote objects that are dead
     """
     # default dead_list inside the function because all objects in method
     # argument lists are init-ed only once globally
     _prnt("ChildProcess::__init__")
     if dead_list is None:
         dead_list = set()
     self._dead_list = dead_list
     self._in = instr
     self._out = outstr
     self._lock = pools.TokenPool(max_size=1)
Exemple #4
0
 def __init__(self, sock, environ, version=76):
     """
     :param socket: The eventlet socket
     :type socket: :class:`eventlet.greenio.GreenSocket`
     :param environ: The wsgi environment
     :param version: The WebSocket spec version to follow (default is 76)
     """
     self.socket = sock
     self.origin = environ.get('HTTP_ORIGIN')
     self.protocol = environ.get('HTTP_WEBSOCKET_PROTOCOL')
     self.path = environ.get('PATH_INFO')
     self.environ = environ
     self.version = version
     self.websocket_closed = False
     self._buf = ""
     self._msgs = collections.deque()
     self._sendlock = pools.TokenPool(1)