当前位置: 首页>>代码示例>>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;未经允许,请勿转载。