本文整理汇总了Python中multiprocessing.pool.ThreadPool.get方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.get方法的具体用法?Python ThreadPool.get怎么用?Python ThreadPool.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.pool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_concurrent_changes_dont_deadlock
# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import get [as 别名]
def test_concurrent_changes_dont_deadlock(self):
self.set_delay(0.1)
def try_and_write(i):
result = requests.post(Server(0).item(i % 3), str(i), timeout=5)
self.assertIn(result.status_code, [201, 503])
threads = ThreadPool(processes=4).map_async(try_and_write, range(20))
try:
threads.get()
except requests.exceptions.Timeout:
self.fail("Request deadlocked and timed out")
示例2: main
# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import get [as 别名]
def main():
if len(sys.argv) < 2:
print_usage()
sys.exit(0)
terms = read_terms(os.path.abspath(sys.argv[1]))
output_queue = Queue.Queue()
output_file = 'output_%s.csv' % time.strftime("%m-%d-%Y-%H%M%S")
output_file = open(output_file, 'wb')
try:
output_writer = ThreadPool(1).apply_async(write_output, (output_queue, output_file))
yahoo_results = ThreadPool(1).apply_async(imap_queue, (yahoo, terms, output_queue))
bing_results = ThreadPool(1).apply_async(imap_queue, (bing, terms, output_queue))
yahoo_results.get()
bing_results.get()
output_queue.join()
finally:
output_file.close()