def test_gevented_connections(self): import gevent from gevent import monkey monkey.patch_all() import psycogreen.gevent psycogreen.gevent.patch_psycopg() os.environ["PYPGWRAP_CLOSE_CONNECTION_ON_EXIT"] = str(True) os.environ["PYPGWRAP_AUTOCOMMIT"] = str(True) config_pool(max_pool=75, pool_expiration=10, url='postgres://*****:*****@0.0.0.0:5533/', pool_manager=ThreadedConnectionPool) def db_command(i): with ContextManager() as context: print("ContextManager ID: " + str(i)) with connection() as db: print("Into of ContextManager ID: " + str(i)) # Setup tables db.execute("SELECT pg_sleep(1);") print("End od ContextManager ID: " + str(i)) threads = [] for i in range(1, 11): print("Current Loop ID: " + str(i)) threads.append(gevent.spawn(db_command, i)) gevent.joinall(threads, timeout=30) for i in range(1, 30): print("Wainting " + str(i) + "s ...") gevent.sleep(1) print("End loop")
def test_gevented_connections(self): import gevent from gevent import monkey; monkey.patch_all() import psycogreen.gevent; psycogreen.gevent.patch_psycopg() os.environ["PYPGWRAP_CLOSE_CONNECTION_ON_EXIT"] = str(True) os.environ["PYPGWRAP_AUTOCOMMIT"] = str(True) config_pool(max_pool=75, pool_expiration=10, url='postgres://*****:*****@0.0.0.0:5533/', pool_manager=ThreadedConnectionPool) def db_command(i): with ContextManager() as context: print("ContextManager ID: " + str(i)) with connection() as db: print("Into of ContextManager ID: " + str(i)) # Setup tables db.execute("SELECT pg_sleep(1);") print("End od ContextManager ID: " + str(i)) threads = [] for i in range(1, 11): print("Current Loop ID: " + str(i)) threads.append(gevent.spawn(db_command, i)) gevent.joinall(threads, timeout=30) for i in range(1, 30): print("Wainting "+str(i)+"s ...") gevent.sleep(1) print("End loop")
def setUp(self): super(MyTestCase, self).setUp() os.environ["PYPGWRAP_CLOSE_CONNECTION_ON_EXIT"] = str(False) config_pool(max_pool=75, pool_expiration=10, url='postgres://*****:*****@localhost:5432/', pool_manager=ThreadedConnectionPool) self.tables = (('doctest_t1', '''id SERIAL PRIMARY KEY, name TEXT NOT NULL, count INTEGER NOT NULL DEFAULT 0, active BOOLEAN NOT NULL DEFAULT true'''), ('doctest_t2', '''id SERIAL PRIMARY KEY, value TEXT NOT NULL, doctest_t1_id INTEGER NOT NULL REFERENCES doctest_t1(id)''' ))
def setUp(self): super(MyTestCase, self).setUp() os.environ["PYPGWRAP_CLOSE_CONNECTION_ON_EXIT"] = str(False) config_pool(max_pool=75, pool_expiration=10, url='postgres://*****:*****@localhost:5432/', pool_manager=ThreadedConnectionPool) self.tables = (('doctest_t1', '''id SERIAL PRIMARY KEY, name TEXT NOT NULL, count INTEGER NOT NULL DEFAULT 0, active BOOLEAN NOT NULL DEFAULT true'''), ('doctest_t2', '''id SERIAL PRIMARY KEY, value TEXT NOT NULL, doctest_t1_id INTEGER NOT NULL REFERENCES doctest_t1(id)''') )