本文整理汇总了Python中multiprocessing.dummy.Pool.apply方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.apply方法的具体用法?Python Pool.apply怎么用?Python Pool.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.dummy.Pool
的用法示例。
在下文中一共展示了Pool.apply方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RunClientCode
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import apply [as 别名]
def RunClientCode(self):
_pool = Pool(1)
try:
_pool.apply(self._client_app.payload)
self._base.NextPage()
self.ShowGoodFinishedDialog()
except:
self.ShowBadFinishedDialog(traceback.format_exc())
示例2: list_records
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import apply [as 别名]
# list of pmid ids
lst = ['9749847','9755759','9757885','9766300','9769004'],'9784814','9800512','9804224','9877391','9879865','9888139','9918973','9919913']
lst = ['9749847']
lst = [['9749847','9755759'],['9757885','9766300','9769004'],['9784814','9800512','9804224','9877391'],['9879865','9888139','9918973','9919913']]
lst = ['9749847','9755759','9757885','9766300','9769004','9784814','9800512','9804224','9877391','9879865','9888139','9918973','9919913']
# define function
def list_records(item):
record = Entrez.read(Entrez.elink(dbfrom="pubmed", db="pmc", LinkName="pubmed_pmc_refs",from_uid=item))
#print(item)
return(record)
pool = mp.Pool(processes=4)
results = [pool.apply(list_records, args=(lst, ))]
print(results)
output = [p.get() for p in results]
print(output)
# define a example function
def rand_string(length, output):
""" Generates a random string of numbers, lower- and uppercase chars. """
rand_str = ''.join(random.choice(
string.ascii_lowercase
+ string.ascii_uppercase
+ string.digits)
for i in range(length))
output.put(rand_str)
示例3:
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import apply [as 别名]
pre_url="https://zh.wikipedia.org"
test_url="https://zh.wikipedia.org/wiki/Category:日本的大學教師"
test2_url="https://zh.wikipedia.org/wiki/Category:各國政治人物"
start_url="https://zh.wikipedia.org/wiki/Category:按國籍分類"
wiki_of =open('process.txt','w+')
urlqueue=Queue.LifoQueue()
start_time=time.time()
start_time=time.time()
root=category(start_url)
while not urlqueue.empty():
pool.apply(new_category, (urlqueue.get(),))
sleep(delay)
pool.close()
pool.join()
print time.time()-start_time
print "All subprocesses done."
wiki_of.close()
# def get_info(url):
# r = requests.get(url)
# print r.text
# print r.encoding