当前位置: 首页>>代码示例>>Python>>正文


Python _thread._local方法代码示例

本文整理汇总了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 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:threading.py

示例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__, {}) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:39,代码来源:test_thread.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:test_autoreload.py


注:本文中的_thread._local方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。