本文整理匯總了Python中_thread._local方法的典型用法代碼示例。如果您正苦於以下問題:Python _thread._local方法的具體用法?Python _thread._local怎麽用?Python _thread._local使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類_thread
的用法示例。
在下文中一共展示了_thread._local方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main_thread
# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import _local [as 別名]
def main_thread():
"""Return the main thread object.
In normal conditions, the main thread is the thread from which the
Python interpreter was started.
"""
return _main_thread
# get thread-local implementation, either from the thread
# module, or from the python fallback
示例2: test_thread_local
# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import _local [as 別名]
def test_thread_local(self):
import _thread as thread
from System.Threading import Thread
x = thread._local()
#--Sanity
x.foo = 42
self.assertEqual(x.foo, 42)
global found
found = None
def f():
global found
found = hasattr(x, 'foo')
thread.start_new_thread(f, ())
while found == None:
Thread.Sleep(100)
self.assertTrue(not found)
self.assertEqual(x.__dict__, {'foo': 42})
try:
x.__dict__ = None
self.fail("Should not be able to set thread._local().__dict__!")
except AttributeError as e:
pass
try:
print(x.bar)
self.fail("There is no 'bar' member on thread._local()")
except AttributeError as e:
pass
del x.foo
self.assertEqual(x.__dict__, {})
示例3: test_resets_trans_real
# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import _local [as 別名]
def test_resets_trans_real(self):
trans_real._translations = {'foo': 'bar'}
trans_real._default = 1
trans_real._active = False
autoreload.reset_translations()
self.assertEqual(trans_real._translations, {})
self.assertIsNone(trans_real._default)
self.assertIsInstance(trans_real._active, _thread._local)