當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。