the database regardless of whether C
extensions are in use or not.
+- postgresql
+ - Use an atomic counter as the "random number"
+ source for server side cursor names;
+ conflicts have been reported in rare cases.
+
- ext
- Added local_attr, remote_attr, attr accessors
to AssociationProxy, providing quick access
"""
-import random
import re
import logging
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()
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()
query._from_obj_alias = sql_util.ColumnAdapter(alias)
-_runid = 1L
-_id_lock = util.threading.Lock()
-
-def _new_runid():
- global _runid
- _id_lock.acquire()
- try:
- _runid += 1
- return _runid
- finally:
- _id_lock.release()
+_new_runid = util.counter()
duck_type_collection, assert_arg_type, symbol, dictlike_iteritems,\
classproperty, set_creation_order, warn_exception, warn, NoneType,\
constructor_copy, methods_equivalent, chop_traceback, asint,\
- generic_repr
+ generic_repr, counter
from deprecations import warn_deprecated, warn_pending_deprecation, \
deprecated, pending_deprecation
return cls(**kw)
+def counter():
+ """Return a threadsafe counter function."""
+
+ lock = threading.Lock()
+ counter = itertools.count(1L)
+
+ def next():
+ lock.acquire()
+ try:
+ return counter.next()
+ finally:
+ lock.release()
+
+ return next
+
def duck_type_collection(specimen, default=None):
"""Given an instance or class, guess if it is or is acting as one of
the basic collection types: list, set and dict. If the __emulates__