def process_method_on_list(method_to_run, items):
'''helper method that processes a method on each listitem with pooling if the system supports it'''
all_items = []
if SUPPORTS_POOL:
pool = ThreadPool()
try:
all_items = pool.map(method_to_run, items)
except Exception:
# catch exception to prevent threadpool running forever
log_msg(format_exc(sys.exc_info()))
log_msg("Error in %s" % method_to_run)
pool.close()
pool.join()
else:
all_items = [method_to_run(item) for item in items]
all_items = filter(None, all_items)
return all_items
评论列表
文章目录