Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GifWriter is failing for Pillow 7.1.0+ #67

Closed
ehpor opened this issue Apr 10, 2020 · 1 comment
Closed

GifWriter is failing for Pillow 7.1.0+ #67

ehpor opened this issue Apr 10, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ehpor
Copy link
Owner

ehpor commented Apr 10, 2020

This is visible in the standard tests. Error does not occur for Pillow 7.0.0. This may have to do with the rewrite of png files in Pillow. The error that occurred with Pillow 7.1.0 was python-pillow/Pillow#4518, for which a fix was released with Pillow 7.1.1. In the new version, the error message has changed to:

    def test_gif_writer():
        grid = make_pupil_grid(256)
    
        mw = GifWriter('test.gif')
    
        for i in range(25):
                field = Field(np.random.randn(grid.size), grid)
    
                plt.clf()
                imshow_field(field)
    
                mw.add_frame()
    
>       mw.close()

tests\test_plotting.py:23:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
hcipy\plotting\animation.py:139: in close
    self.convert()
hcipy\plotting\animation.py:132: in convert
    return self.convert_to_gif(self.filename, self.path_to_frames, self.framerate, num_files_to_convert=self.num_frames)
hcipy\plotting\animation.py:125: in convert_to_gif
    loop=0)
C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py:2134: in save
    save_handler(self, fp, filename)
C:\ProgramData\Anaconda3\lib\site-packages\PIL\GifImagePlugin.py:499: in _save_all
    _save(im, fp, filename, save_all=True)
C:\ProgramData\Anaconda3\lib\site-packages\PIL\GifImagePlugin.py:510: in _save
    if not save_all or not _write_multiple_frames(im, fp, palette):
C:\ProgramData\Anaconda3\lib\site-packages\PIL\GifImagePlugin.py:430: in _write_multiple_frames
    for im_frame in ImageSequence.Iterator(imSequence):
C:\ProgramData\Anaconda3\lib\site-packages\PIL\ImageSequence.py:49: in __next__
    self.im.seek(self.position)
C:\ProgramData\Anaconda3\lib\site-packages\PIL\PngImagePlugin.py:748: in seek
    self._seek(f)
C:\ProgramData\Anaconda3\lib\site-packages\PIL\PngImagePlugin.py:784: in _seek
    ImageFile._safe_read(self.fp, self.__prepare_idat)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

fp = <_io.BufferedReader name='test.gif_frames\\00000.png'>, size = 8192

    def _safe_read(fp, size):
        """
        Reads large blocks in a safe way.  Unlike fp.read(n), this function
        doesn't trust the user.  If the requested size is larger than
        SAFEBLOCK, the file is read block by block.
    
        :param fp: File handle.  Must implement a <b>read</b> method.
        :param size: Number of bytes to read.
        :returns: A string containing up to <i>size</i> bytes of data.
        """
        if size <= 0:
            return b""
        if size <= SAFEBLOCK:
>           return fp.read(size)
E           ValueError: read of closed file

C:\ProgramData\Anaconda3\lib\site-packages\PIL\ImageFile.py:549: ValueError

I'm not sure yet whether this is a bug in HCIPy or in Pillow.

@ehpor ehpor added the bug Something isn't working label Apr 10, 2020
@ehpor ehpor self-assigned this Apr 10, 2020
@ehpor ehpor closed this as completed in e6dcd26 Apr 11, 2020
@ehpor
Copy link
Owner Author

ehpor commented Apr 11, 2020

Bug was in Pillow, and was fixed already but not yet released. python-pillow/Pillow#4543 suggested a workaround that seems to work fine for all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant