summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Kirtland <jek@discorporate.us>2007-08-15 23:11:47 +0000
committerJason Kirtland <jek@discorporate.us>2007-08-15 23:11:47 +0000
commit46535b25a642b596c1f43217fe00f6205bcc0ecb (patch)
treedc721e69f2d0b1f4a97b2f45f4071b1a3d63c831
parentfddc687348fe5e5b36b3207e5ff454bb901b64bc (diff)
downloadsqlalchemy-46535b25a642b596c1f43217fe00f6205bcc0ecb.tar.gz
use threading.local if available
speed up ThreadLocal for python 2.3 [ticket:743] clean in topo (in patch from [ticket:743])
-rw-r--r--lib/sqlalchemy/topological.py2
-rw-r--r--lib/sqlalchemy/util.py46
-rw-r--r--test/testlib/config.py2
3 files changed, 28 insertions, 22 deletions
diff --git a/lib/sqlalchemy/topological.py b/lib/sqlalchemy/topological.py
index b744edaa5..a13923885 100644
--- a/lib/sqlalchemy/topological.py
+++ b/lib/sqlalchemy/topological.py
@@ -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:
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py
index 82815f101..37dfeb211 100644
--- a/lib/sqlalchemy/util.py
+++ b/lib/sqlalchemy/util.py
@@ -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."""
diff --git a/test/testlib/config.py b/test/testlib/config.py
index 719dcf6c0..8f5a39d86 100644
--- a/test/testlib/config.py
+++ b/test/testlib/config.py
@@ -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)")