summaryrefslogtreecommitdiffstats
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-12-18 19:07:19 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-12-18 19:07:19 (GMT)
commit7e71fa5cfa250968eafdb77356621e3a9bbb0648 (patch)
tree994cd01f51395f71051589ad32f3af0bfb2b779e /Lib/decimal.py
parent193814c3082f1b81772009f9b7545278f16c3428 (diff)
downloadcpython-7e71fa5cfa250968eafdb77356621e3a9bbb0648.zip
cpython-7e71fa5cfa250968eafdb77356621e3a9bbb0648.tar.gz
cpython-7e71fa5cfa250968eafdb77356621e3a9bbb0648.tar.bz2
Bug #1083645
* The decimal module wouldn't load on builds without threads.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index f9c065f..05bdc99 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -134,7 +134,6 @@ __all__ = [
'setcontext', 'getcontext'
]
-import threading
import copy
#Rounding
@@ -385,7 +384,19 @@ _condition_map = {ConversionSyntax:InvalidOperation,
# The getcontext() and setcontext() function manage access to a thread-local
# current context. Py2.4 offers direct support for thread locals. If that
# is not available, use threading.currentThread() which is slower but will
-# work for older Pythons.
+# work for older Pythons. If threads are not part of the build, create a
+# mock threading object with threading.local() returning the module namespace.
+
+try:
+ import threading
+except ImportError:
+ # Python was compiled without threads; create a mock object instead
+ import sys
+ class MockThreading:
+ def local(self, sys=sys):
+ return sys.modules[__name__]
+ threading = MockThreading()
+ del sys, MockThreading
try:
threading.local