在python循环中清除内存 [英] Clear memory in python loop
本文介绍了在python循环中清除内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将期货作为期货
导入concurrent.futures。 ThreadPoolExecutor(max_workers = 100)作为执行者:
fs = [链接中url的executor.submit(get_data,url)]
为i,f在枚举中(futures.as_completed(fs)):
x =(f.result())
results.append(x)
del x
del f
$ b $ get_data - 使用请求的简单函数
解决方案
我的解决方案是这样的:
导入并发期货作为期货
#将原始大表分成小批量
batchurlList = [grandUrlList [x:x + batchSize],范围为(0,len(grandUrlList),batchSize)]
为batchurlList中的tmpurlList:
与futures.ThreadPoolExecutor(max_workers = 100)作为执行者:
myfuture = {executor.submit(myFunction,url):url在tmpurlList中的url}
for future for future.as_completed(myfuture,timeout = 60):
originalUrl = myfuture [future]
results.append(future.result())
How i can clear memory in this python loop ?
import concurrent.futures as futures
with futures.ThreadPoolExecutor(max_workers=100) as executor:
fs = [executor.submit(get_data, url) for url in link]
for i, f in enumerate(futures.as_completed(fs)):
x= (f.result())
results.append(x)
del x
del f
get_data - simple function wich using requests
解决方案
My solution would be as such:
import concurrent.futures as futures
#split the original grand list into smaller batches
batchurlList = [grandUrlList[x:x+batchSize] for x in range(0, len(grandUrlList), batchSize)]
for tmpurlList in batchurlList:
with futures.ThreadPoolExecutor(max_workers=100) as executor:
myfuture = {executor.submit(myFunction, url): url for url in tmpurlList}
for future in futures.as_completed(myfuture, timeout=60):
originalUrl = myfuture[future]
results.append(future.result())
这篇关于在python循环中清除内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文