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

Matplotlib savefig() closes BytesIO object when saving in postscript format #1862

Merged
merged 1 commit into from Mar 27, 2013

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Mar 27, 2013

In Python 3, I am seeing the following bug:

In [1]: from io import BytesIO

In [2]: import matplotlib.pyplot as plt

In [3]: b = BytesIO()

In [4]: fig = plt.figure()

In [5]: ax = fig.add_subplot(1,1,1)

In [6]: ax.plot([1,2,3])
Out[6]: [<matplotlib.lines.Line2D at 0x104a90990>]

In [7]: fig.savefig(b, format='eps')

In [8]: b.seek(0)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-22abda41fe70> in <module>()
----> 1 b.seek(0)

ValueError: I/O operation on closed file.

As far as I can tell, this does not occur with StringIO in Python 2.x.

@mdboom - is this related to #1779?

@mdboom
Copy link
Member

mdboom commented Mar 27, 2013

Nope -- this bug is only on master, and perhaps related to #1826.

…handles passed to it on Python 3. The TextIOWrapper that handles the encoding from unicode to ascii needs to be detached before its destructor is called, otherwise it will call close on the underlying file object. Also cleans up how with statements are handled to avoid the sometimes problematic null contextmanager.
@astrofrog
Copy link
Contributor Author

@mdboom - this works for me - thanks!

mdboom added a commit that referenced this pull request Mar 27, 2013
Matplotlib savefig() closes BytesIO object when saving in postscript format
@mdboom mdboom merged commit ca476df into matplotlib:master Mar 27, 2013
HubertHolin pushed a commit to HubertHolin/matplotlib that referenced this pull request Apr 7, 2013
…handles passed to it on Python 3. The TextIOWrapper that handles the encoding from unicode to ascii needs to be detached before its destructor is called, otherwise it will call close on the underlying file object. Also cleans up how with statements are handled to avoid the sometimes problematic null contextmanager.
pelson pushed a commit to pelson/matplotlib that referenced this pull request Apr 29, 2013
…handles passed to it on Python 3. The TextIOWrapper that handles the encoding from unicode to ascii needs to be detached before its destructor is called, otherwise it will call close on the underlying file object. Also cleans up how with statements are handled to avoid the sometimes problematic null contextmanager.
@mdboom mdboom deleted the ps-file-closing branch August 7, 2014 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants