當前位置: 首頁>>代碼示例>>Python>>正文


Python _thread.TIMEOUT_MAX屬性代碼示例

本文整理匯總了Python中_thread.TIMEOUT_MAX屬性的典型用法代碼示例。如果您正苦於以下問題:Python _thread.TIMEOUT_MAX屬性的具體用法?Python _thread.TIMEOUT_MAX怎麽用?Python _thread.TIMEOUT_MAX使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在_thread的用法示例。


在下文中一共展示了_thread.TIMEOUT_MAX屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_timeout

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import TIMEOUT_MAX [as 別名]
def test_timeout(self):
        lock = self.locktype()
        # Can't set timeout if not blocking
        self.assertRaises(ValueError, lock.acquire, 0, 1)
        # Invalid timeout values
        self.assertRaises(ValueError, lock.acquire, timeout=-100)
        self.assertRaises(OverflowError, lock.acquire, timeout=1e100)
        self.assertRaises(OverflowError, lock.acquire, timeout=TIMEOUT_MAX + 1)
        # TIMEOUT_MAX is ok
        lock.acquire(timeout=TIMEOUT_MAX)
        lock.release()
        t1 = time.time()
        self.assertTrue(lock.acquire(timeout=5))
        t2 = time.time()
        # Just a sanity test that it didn't actually wait for the timeout.
        self.assertLess(t2 - t1, 5)
        results = []
        def f():
            t1 = time.time()
            results.append(lock.acquire(timeout=0.5))
            t2 = time.time()
            results.append(t2 - t1)
        Bunch(f, 1).wait_for_finished()
        self.assertFalse(results[0])
        self.assertTimeout(results[1], 0.5) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,代碼來源:lock_tests.py

示例2: test_timeout

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import TIMEOUT_MAX [as 別名]
def test_timeout(self):
        lock = self.locktype()
        # Can't set timeout if not blocking
        self.assertRaises(ValueError, lock.acquire, 0, 1)
        # Invalid timeout values
        self.assertRaises(ValueError, lock.acquire, timeout=-100)
        self.assertRaises(OverflowError, lock.acquire, timeout=1e100)
        self.assertRaises(OverflowError, lock.acquire, timeout=TIMEOUT_MAX + 1)
        # TIMEOUT_MAX is ok
        lock.acquire(timeout=TIMEOUT_MAX)
        lock.release()
        t1 = time.monotonic()
        self.assertTrue(lock.acquire(timeout=5))
        t2 = time.monotonic()
        # Just a sanity test that it didn't actually wait for the timeout.
        self.assertLess(t2 - t1, 5)
        results = []
        def f():
            t1 = time.monotonic()
            results.append(lock.acquire(timeout=0.5))
            t2 = time.monotonic()
            results.append(t2 - t1)
        Bunch(f, 1).wait_for_finished()
        self.assertFalse(results[0])
        self.assertTimeout(results[1], 0.5) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:27,代碼來源:lock_tests.py

示例3: download_thread

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import TIMEOUT_MAX [as 別名]
def download_thread(url, path, exfile_name=None, exfile_dir=None):
    tag = 'Download_Thread'
    wait_for_limit()
    local_path = path
    give_it_a_sign = False
    local_filename = url.split('/')[-1]
    if local_filename.endswith('zip'):
        give_it_a_sign = True
    if exfile_dir is not None:
        local_path += exfile_dir + global_symbol
    if exfile_name is not None:
        local_filename = exfile_name + "-" + local_filename
    path_output = local_path + local_filename
    print_with_tag(tag, ["File Location:" + path_output])
    if not os.path.exists(local_path):
        print_with_tag(tag, "Folder doesn't exists!!")
        os.makedirs(local_path)
        print_with_tag(tag, "Folder Created.")

    retry_count = 0
    while True:
        try:
            _thread.TIMEOUT_MAX = 60
            _thread.start_new_thread(download_file, (url, path_output, give_it_a_sign))
        except:
            print_with_tag(tag, "Error.")
            if retry_count == 3:
                print_with_tag(tag, "Not wokring..")
                print_with_tag(tag, "Skip!!")
            else:
                print_with_tag(tag, "Starting retry..")
                retry_count += 1
        else:
            print_with_tag(tag, "Download thread successfully started!")
            break
    print_with_tag(tag, ['Threads_count:', str(current_threads)]) 
開發者ID:SuzukiHonoka,項目名稱:Starx_Pixiv_Collector,代碼行數:38,代碼來源:start.py


注:本文中的_thread.TIMEOUT_MAX屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。