def handler(request): if debug: global count count += 1 index = count print "start-%d" % index, pool.connected_count, len(pool.free_items), pool.waittings conn = yield pool.get() if debug: print "get-%d" % index, pool.connected_count, len(pool.free_items), pool.waittings try: with conn.cursor(True) as cur: yield cur.execute("SELECT * FROM url_source where id>%s LIMIT 1", (10000 + randint(1000, 5000),)) rs = yield cur.fetchall() finally: yield pool.put(conn) # print cur.execute('delete from url_source where id=%s', (1686,)) # print conn.commit() if debug: print "end-%d" % index, pool.connected_count, len(pool.free_items), pool.waittings cookie = request.get_cookie("testcookie") r = HTTPReponse( """Hello world, %s, cookie: %s, request: %s data: %s connected: %s, pool left: %s Schedule: %s""" % (datetime.now(), cookie, request, rs[0], pool.connected_count, len(pool.free_items), schedule), "text/plain", ) r.set_cookie("testcookie", "%s" % time.time()) yield r
def handler(request): cur = conn.cursor() try: cur.execute("SELECT * FROM url_source where id>%s LIMIT 1", (10000 + randint(1000, 5000),)) rs = cur.fetchall() finally: cur.close() cookie = request.get_cookie('testcookie') r = HTTPReponse("""Hello world, %s, cookie: %s, request: %s data: %s Schedule: %s""" % \ (datetime.now(), cookie, request, rs[0], schedule), 'text/plain') r.set_cookie('testcookie', '%s' % time.time()) yield r