[Python-checkins] python/dist/src/Lib decimal.py,1.31,1.32

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sat Dec 18 20:07:23 CET 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv562

Modified Files:
	decimal.py 
Log Message:
Bug #1083645

* The decimal module wouldn't load on builds without threads.



Index: decimal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/decimal.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- decimal.py	24 Nov 2004 07:28:48 -0000	1.31
+++ decimal.py	18 Dec 2004 19:07:15 -0000	1.32
@@ -134,7 +134,6 @@
     'setcontext', 'getcontext'
 ]
 
-import threading
 import copy
 
 #Rounding
@@ -385,7 +384,19 @@
 # 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



More information about the Python-checkins mailing list