Python 映像操作不适用于多处理

Python 映像操作不适用于多处理,python,multiprocessing,python-imaging-library,Python,Multiprocessing,Python Imaging Library,我之前发布了一个问题,其代码由于类似原因无法工作。它没有引起太多的注意,所以我删除了它,并找到了问题的最小子集 以代码为例: 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 man

我之前发布了一个问题,其代码由于类似原因无法工作。它没有引起太多的注意,所以我删除了它,并找到了问题的最小子集

以代码为例:

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
(即不使用任何
多处理
),则输出为:

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'
C:\Users\H.P\Downloads\states\General>python mptest.py
multiprocessing.pool.RemoteTraceback:
"""
回溯(最近一次呼叫最后一次):
文件“C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py”,第119行,在worker中
结果=(True,func(*args,**kwds))
文件“C:\Users\H.P\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py”,第47行,在starmapstar中
返回列表(itertools.starmap(args[0],args[1]))
文件“C:\Users\H.P\Downloads\states\General\mptest.py”,第5行,f
im.seek(i)
文件“C:\Users\H.P\AppData\Local\Programs\Python\36\lib\site packages\PIL\TiffImagePlugin.py”,第998行,位于seek中
如果不是自搜索检查(帧):
文件“C:\Users\H.P\AppData\Local\Programs\Python\36\lib\site packages\PIL\ImageFile.py”,第276行,在搜索检查中
如果(帧
这个
\u min\u帧
源于
ImageFile.py
文件的
\uuuu init\uuu
。因此,当调用它时,它一定调用了
\uu init\uu()方法


为什么会发生这种情况?这是
PIL
中的一个错误吗?

您是否也得到了
单线程
的问题?您的意思是不使用
多处理
?问题中已经说明了。我不明白您是否在陈述其他内容。