我在第三轮(while 循环)中执行的代码有什么问题nfind
,返回 MemoryError 符合CACHE[sha] = number
?在系统上有足够的内存,并且在 while 循环的每一端我清除分配的内存,但它在第三次while
循环中返回错误。如果您运行这些代码,在某些情况下,我认为有必要更改XRAN= 2**23
为更大或更小的指数(一或二),以产生错误。请帮助和建议。
from multiprocessing import Pool
from hashlib import sha256
from struct import pack
import gc
XRAN= 2**23
def compsha(number):
return number, sha256(pack("Q", number)).digest()
if __name__ == '__main__':
gc.enable()
nfind = 1
while (nfind > 0):
print(nfind)
CACHE = {}
pool = Pool()
for i, output in enumerate(pool.imap_unordered(compsha, xrange((nfind-1)*XRAN, nfind*XRAN), 2)):
number, sha = output
CACHE[sha] = number
pool.close()
pool.join()
if nfind != 0 :
nfind = nfind + 1
del CACHE
=======================================================
>>>
1
2
Traceback (most recent call last):
File "D:\Python27\free_pool.py", line 20, in <module>
CACHE[sha] = number
MemoryError