8000 Detach SVG TextIOWrapper after writing. · rmlopes/matplotlib@1810f1f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1810f1f

Browse files
committed
Detach SVG TextIOWrapper after writing.
This leaves the owned-by-caller file object alone instead of forcing it to close as well. Fixes matplotlib#6926, though I'm not entirely sure why only the cleanup decorator + usetex triggers it.
1 parent 682a331 commit 1810f1f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/matplotlib/backends/backend_svg.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,22 @@ def print_svg(self, filename, *args, **kwargs):
12051205
svgwriter = io.TextIOWrapper(svgwriter, 'utf-8')
12061206
else:
12071207
svgwriter = codecs.getwriter('utf-8')(svgwriter)
1208+
detach = True
1209+
else:
1210+
detach = False
1211+
1212+
result = self._print_svg(filename, svgwriter, **kwargs)
1213+
1214+
# Detach underlying stream from wrapper so that it remains open in the
1215+
# caller.
1216+
if detach:
1217+
if six.PY3:
1218+
svgwriter.detach()
1219+
else:
1220+
svgwriter.reset()
1221+
svgwriter.stream = io.BytesIO()
12081222

1209-
return self._print_svg(filename, svgwriter, **kwargs)
1223+
return result
12101224

12111225
def print_svgz(self, filename, *args, **kwargs):
12121226
if is_string_like(filename):

0 commit comments

Comments
 (0)
0