Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ef66debd
Kaydet (Commit)
ef66debd
authored
Tem 14, 2004
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use threading.local() instead of threading.currentThread().
üst
99148e7e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
21 deletions
+57
-21
decimal.py
Lib/decimal.py
+57
-21
No files found.
Lib/decimal.py
Dosyayı görüntüle @
ef66debd
...
@@ -374,30 +374,66 @@ _condition_map = {ConversionSyntax:InvalidOperation,
...
@@ -374,30 +374,66 @@ _condition_map = {ConversionSyntax:InvalidOperation,
##### Context Functions #######################################
##### Context Functions #######################################
#To fix reloading, force it to create a new context
# The getcontext() and setcontext() function manage access to a thread-local
#Old contexts have different exceptions in their dicts, making problems.
# current context. Py2.4 offers direct support for thread locals. If that
if
hasattr
(
threading
.
currentThread
(),
'__decimal_context__'
):
# is not available, use threading.currentThread() which is slower but will
del
threading
.
currentThread
()
.
__decimal_context__
# work for older Pythons.
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
()
:
try
:
"""Returns this thread's context.
threading
.
local
If this thread does not yet have a context, returns
except
AttributeError
:
a new context and sets this thread's context.
New contexts are copies of DefaultContext.
#To fix reloading, force it to create a new context
"""
#Old contexts have different exceptions in their dicts, making problems.
try
:
if
hasattr
(
threading
.
currentThread
(),
'__decimal_context__'
):
return
threading
.
currentThread
()
.
__decimal_context__
del
threading
.
currentThread
()
.
__decimal_context__
except
AttributeError
:
context
=
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
threading
.
currentThread
()
.
__decimal_context__
=
context
return
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
##### Decimal class ###########################################
##### Decimal class ###########################################
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment