Ранее я опубликовал вопрос, код которого не работает по аналогичным причинам.Это не привлекло большого внимания, поэтому я удалил его и нашел минимальное подмножество проблемы.
Рассмотрим код:
from multiprocessing import Pool
from PIL import Image
import PIL.TiffImagePlugin as tiff
def f(im,i):
im.seek(i)
print(i)
manual = False
if (__name__=='__main__' and not manual):
p = Pool()
im = Image.open('page.tiff')
im.load()
print(p.starmap(f,[(im,0),(im,1),(im,2),(im,3)]))
if(manual):
im = Image.open('page.tiff')
f(im,0)
f(im,1)
f(im,2)
f(im,3)
Если manual = True
(то есть без использования multiprocessing
), то вывод будет:
C:\Users\H.P\Downloads\states\General>python mptTest.py
0
1
2
3
Принимая во внимание, чтоесли manual = False
, то я получаю ошибку:
C:\Users\H.P\Downloads\states\General>python mptTest.py
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py", line 47, in starmapstar
return list(itertools.starmap(args[0], args[1]))
File "C:\Users\H.P\Downloads\states\General\mptTest.py", line 5, in f
im.seek(i)
File "C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\TiffImagePlugin.py", line 998, in seek
if not self._seek_check(frame):
File "C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\site-packages\PIL\ImageFile.py", line 276, in _seek_check
if (frame < self._min_frame or
AttributeError: 'TiffImageFile' object has no attribute '_min_frame'
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "mptTest.py", line 15, in <module>
print(p.starmap(f,[(im,0),(im,1),(im,2),(im,3)]))
File "C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py", line 274, in starmap
return self._map_async(func, iterable, starmapstar, chunksize).get()
File "C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py", line 644, in get
raise self._value
AttributeError: 'TiffImageFile' object has no attribute '_min_frame'
Этот _min_frame
происходит из __init__
файла ImageFile.py
.Поэтому, когда он вызывается, он должен был вызвать метод __init__()
.
Почему это происходит?Это ошибка в PIL
?