]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #1083645
authorRaymond Hettinger <python@rcn.com>
Sat, 18 Dec 2004 19:07:19 +0000 (19:07 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 18 Dec 2004 19:07:19 +0000 (19:07 +0000)
* The decimal module wouldn't load on builds without threads.

Lib/decimal.py
Lib/test/test_decimal.py

index f9c065f677dbd1f740b4479902818fba7284ca6a..05bdc99f4e0da60b8623aa0d66e0c0da6adf8bc7 100644 (file)
@@ -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
index 06e8b9dd1c98541465065aa7ca0dce51d1622884..f523a721316a5d5762d635921ce72794010eb975 100644 (file)
@@ -32,8 +32,11 @@ import os, sys
 import pickle, copy
 from decimal import *
 from test.test_support import TestSkipped, run_unittest, run_doctest, is_resource_enabled
-import threading
 import random
+try:
+    import threading
+except ImportError:
+    threading = None
 
 # Useful Test Constant
 Signals = getcontext().flags.keys()
@@ -724,7 +727,11 @@ def thfunc2(cls):
 class DecimalUseOfContextTest(unittest.TestCase):
     '''Unit tests for Use of Context cases in Decimal.'''
 
-    import threading
+    try:
+        import threading
+    except ImportError:
+        threading = None
+
     # Take care executing this test from IDLE, there's an issue in threading
     # that hangs IDLE and I couldn't find it
 
@@ -745,6 +752,9 @@ class DecimalUseOfContextTest(unittest.TestCase):
         self.finish1.wait()
         return
 
+    if threading is None:
+        del test_threading
+
 
 class DecimalUsabilityTest(unittest.TestCase):
     '''Unit tests for Usability cases of Decimal.'''