425,430d424 < # 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.current_thread() which is slower but will < # work for older Pythons. If threads are not part of the build, create a < # mock threading object with threading.local() returning the module namespace. < 434,444c428 < # Python was compiled without threads; create a mock object instead < class MockThreading(object): < def local(self, sys=sys): < return sys.modules[__name__] < threading = MockThreading() < del MockThreading < < try: < threading.local < < except AttributeError: --- > import dummy_threading 446,496c430,444 < # To fix reloading, force it to create a new context < # Old contexts have different exceptions in their dicts, making problems. < if hasattr(threading.current_thread(), '__decimal_context__'): < del threading.current_thread().__decimal_context__ < < def setcontext(context): < """Set this thread's context to context.""" < if context in (DefaultContext, BasicContext, ExtendedContext): < context = context.copy() < context.clear_flags() < threading.current_thread().__decimal_context__ = context < < def getcontext(): < """Returns this thread's context. < < If this thread does not yet have a context, returns < a new context and sets this thread's context. < New contexts are copies of DefaultContext. < """ < try: < return threading.current_thread().__decimal_context__ < except AttributeError: < context = Context() < threading.current_thread().__decimal_context__ = context < return context < < else: < < local = threading.local() < if hasattr(local, '__decimal_context__'): < del local.__decimal_context__ < < def getcontext(_local=local): < """Returns this thread's context. < < If this thread does not yet have a context, returns < a new context and sets this thread's context. < New contexts are copies of DefaultContext. < """ < try: < return _local.__decimal_context__ < except AttributeError: < context = Context() < _local.__decimal_context__ = context < return context < < def setcontext(context, _local=local): < """Set this thread's context to context.""" < if context in (DefaultContext, BasicContext, ExtendedContext): < context = context.copy() < context.clear_flags() --- > local = threading.local() > if hasattr(local, '__decimal_context__'): > del local.__decimal_context__ > > def getcontext(_local=local): > """Returns this thread's context. > > If this thread does not yet have a context, returns > a new context and sets this thread's context. > New contexts are copies of DefaultContext. > """ > try: > return _local.__decimal_context__ > except AttributeError: > context = Context() 497a446,453 > return context > > def setcontext(context, _local=local): > """Set this thread's context to context.""" > if context in (DefaultContext, BasicContext, ExtendedContext): > context = context.copy() > context.clear_flags() > _local.__decimal_context__ = context 499c455 < del threading, local # Don't contaminate the namespace --- > del threading, local # Don't contaminate the namespace 706,707c662 < # @classmethod, but @decorator is not valid Python 2.3 syntax, so < # don't use it (see notes on Py2.3 compatibility at top of file) --- > @classmethod 746d700 < from_float = classmethod(from_float)