[Python-checkins] python/dist/src/Lib decimal.py,1.18,1.19

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed Jul 14 23:04:30 CEST 2004


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

Modified Files:
	decimal.py 
Log Message:
Use threading.local() instead of threading.currentThread().



Index: decimal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/decimal.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** decimal.py	14 Jul 2004 19:56:56 -0000	1.18
--- decimal.py	14 Jul 2004 21:04:27 -0000	1.19
***************
*** 375,402 ****
  ##### Context Functions #######################################
  
! #To fix reloading, force it to create a new context
! #Old contexts have different exceptions in their dicts, making problems.
! if hasattr(threading.currentThread(), '__decimal_context__'):
!     del threading.currentThread().__decimal_context__
  
! def setcontext(context):
!     """Set this thread's context to context."""
!     if context in (DefaultContext, BasicContext, ExtendedContext):
!         context = context.copy()
!     threading.currentThread().__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.currentThread().__decimal_context__
!     except AttributeError:
!         context = Context()
          threading.currentThread().__decimal_context__ = context
!         return context
  
  
--- 375,438 ----
  ##### Context Functions #######################################
  
! # 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.
  
! try:
!     threading.local
  
! except AttributeError:
  
!     #To fix reloading, force it to create a new context
!     #Old contexts have different exceptions in their dicts, making problems.
!     if hasattr(threading.currentThread(), '__decimal_context__'):
!         del threading.currentThread().__decimal_context__
! 
!     def setcontext(context):
!         """Set this thread's context to context."""
!         if context in (DefaultContext, BasicContext, ExtendedContext):
!             context = context.copy()
          threading.currentThread().__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.currentThread().__decimal_context__
!         except AttributeError:
!             context = Context()
!             threading.currentThread().__decimal_context__ = context
!             return context
! 
! else:
! 
!     local = threading.local()
! 
!     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()
!         _local.__decimal_context__ = context
! 
!     del threading, local        # Don't contaminate the namespace
  
  



More information about the Python-checkins mailing list