From c13dee04139837bdd6ff5ff70ebeca09692ee384 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 6 Aug 2011 14:21:19 -0400 Subject: - use itertools.count() plus mutex for Query _new_runid, psycopg2 server side cursor names, mentinoed in [ticket:2247] --- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py') diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 2a3b4297c..22487a359 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -97,7 +97,6 @@ The psycopg2 dialect will log Postgresql NOTICE messages via the """ -import random import re import logging @@ -165,6 +164,8 @@ SERVER_SIDE_CURSOR_RE = re.compile( r'\s*SELECT', re.I | re.UNICODE) +_server_side_id = util.counter() + class PGExecutionContext_psycopg2(PGExecutionContext): def create_cursor(self): # TODO: coverage for server side cursors + select.for_update() @@ -187,7 +188,7 @@ class PGExecutionContext_psycopg2(PGExecutionContext): if is_server_side: # use server-side cursors: # http://lists.initd.org/pipermail/psycopg/2007-January/005251.html - ident = "c_%s_%s" % (hex(id(self))[2:], hex(random.randint(0, 65535))[2:]) + ident = "c_%s_%s" % (hex(id(self))[2:], hex(_server_side_id())[2:]) return self._dbapi_connection.cursor(ident) else: return self._dbapi_connection.cursor() -- cgit v1.2.1