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