diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-06 14:21:19 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-06 14:21:19 -0400 |
| commit | c13dee04139837bdd6ff5ff70ebeca09692ee384 (patch) | |
| tree | fb9233c0367956f5579934b5ef785d8f1589e8be /lib/sqlalchemy/util | |
| parent | 669d0c47f8806173261a365b66cae6edf73287cb (diff) | |
| download | sqlalchemy-c13dee04139837bdd6ff5ff70ebeca09692ee384.tar.gz | |
- use itertools.count() plus mutex for Query _new_runid, psycopg2 server
side cursor names, mentinoed in [ticket:2247]
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/__init__.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 4b7a43752..c78cddf77 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -27,7 +27,7 @@ from langhelpers import iterate_attributes, class_hierarchy, \ 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 diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index c3a358220..82f28f8ec 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -610,6 +610,21 @@ def constructor_copy(obj, cls, **kw): 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__ |
