本文整理汇总了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)