]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
use threading.local if available
authorJason Kirtland <jek@discorporate.us>
Wed, 15 Aug 2007 23:11:47 +0000 (23:11 +0000)
committerJason Kirtland <jek@discorporate.us>
Wed, 15 Aug 2007 23:11:47 +0000 (23:11 +0000)
speed up ThreadLocal for python 2.3 [ticket:743]
clean in topo (in patch from [ticket:743])

lib/sqlalchemy/topological.py
lib/sqlalchemy/util.py
test/testlib/config.py

index b744edaa575c3de38c1082a6a5b2aabf3a3f77ee..a13923885fffcc5c057e0e60ad4b965c0a661e0a 100644 (file)
@@ -196,7 +196,7 @@ class QueueDependencySorter(object):
         for n in nodes.values():
             if not edges.has_parents(n):
                 queue.append(n)
-        cycles = {}
+
         output = []
         while nodes:
             if not queue:
index 82815f1015e6d0bc66c74c96be901118941466bc..37dfeb2114360fcf7ba3def06d780b173f319978 100644 (file)
@@ -366,26 +366,32 @@ class OrderedDict(dict):
         self._list.remove(item[0])
         return item
 
-class ThreadLocal(object):
-    """An object in which attribute access occurs only within the context of the current thread."""
-
-    def __init__(self):
-        self.__dict__['_tdict'] = {}
-
-    def __delattr__(self, key):
-        try:
-            del self._tdict["%d_%s" % (thread.get_ident(), key)]
-        except KeyError:
-            raise AttributeError(key)
-
-    def __getattr__(self, key):
-        try:
-            return self._tdict["%d_%s" % (thread.get_ident(), key)]
-        except KeyError:
-            raise AttributeError(key)
-
-    def __setattr__(self, key, value):
-        self._tdict["%d_%s" % (thread.get_ident(), key)] = value
+try:
+    from threading import local as ThreadLocal
+except ImportError:
+    try:
+        from dummy_threading import local as ThreadLocal
+    except ImportError:
+        class ThreadLocal(object):
+            """An object in which attribute access occurs only within the context of the current thread."""
+
+            def __init__(self):
+                self.__dict__['_tdict'] = {}
+
+            def __delattr__(self, key):
+                try:
+                    del self._tdict[(thread.get_ident(), key)]
+                except KeyError:
+                    raise AttributeError(key)
+
+            def __getattr__(self, key):
+                try:
+                    return self._tdict[(thread.get_ident(), key)]
+                except KeyError:
+                    raise AttributeError(key)
+
+            def __setattr__(self, key, value):
+                self._tdict[(thread.get_ident(), key)] = value
 
 class DictDecorator(dict):
     """A Dictionary that delegates items not found to a second wrapped dictionary."""
index 719dcf6c0e07bea0e0fc46ad4fa04072aa8e3693..8f5a39d866641cc3f76b6f6d847582b17356fa77 100644 (file)
@@ -109,7 +109,7 @@ opt("--mockpool", action="store_true", dest="mockpool",
     help="Use mock pool (asserts only one connection used)")
 opt("--enginestrategy", action="callback", type="string",
     callback=_engine_strategy,
-    help="Engine strategy (plain or threadlocal, defaults toplain)")
+    help="Engine strategy (plain or threadlocal, defaults to plain)")
 opt("--reversetop", action="store_true", dest="reversetop", default=False,
     help="Reverse the collection ordering for topological sorts (helps "
           "reveal dependency issues)")