예제 #1
0
        with pool.connection(**options) as conn:
            print ("conn: pool size: %s" % pool.size)

            sent = conn.send(data)
            echo_data = conn.recv(1024)
            assert data == echo_data

    start = time.time()
    jobs = [gevent.spawn(runpool, "blahblah") for _ in xrange(50)]

    gevent.joinall(jobs)
    delay = time.time() - start

    print ("final pool size: %s" % pool.size)

    with pool.connection(**options) as conn:
        print ("conn: pool size: %s" % pool.size)

        sent = conn.send("hello")
        echo_data = conn.recv(1024)
        assert "hello" == echo_data

    print ("final pool size: %s" % pool.size)

########NEW FILE########
__FILENAME__ = test_threaded
# -*- coding: utf-8 -
#
# This file is part of socketpool.
# See the NOTICE for more information.
예제 #2
0
    options = {'host': 'localhost', 'port': 6000}
    pool = ConnectionPool(factory=TcpConnector, backend="gevent")
    server = StreamServer(('localhost', 6000), echo)
    gevent.spawn(server.serve_forever)

    def runpool(data):
        with pool.connection(**options) as conn:
            print("conn: pool size: %s" % pool.size)

            sent = conn.send(data)
            echo_data = conn.recv(1024)
            assert data == echo_data

    start = time.time()
    jobs = [gevent.spawn(runpool, "blahblah") for _ in xrange(50)]

    gevent.joinall(jobs)
    delay = time.time() - start

    print("final pool size: %s" % pool.size)

    with pool.connection(**options) as conn:
        print("conn: pool size: %s" % pool.size)

        sent = conn.send("hello")
        echo_data = conn.recv(1024)
        assert "hello" == echo_data

    print("final pool size: %s" % pool.size)