10000 Overhaul external process calls by tomspur · Pull Request #7572 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Overhaul external process calls #7572

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

Merged
merged 16 commits into from
Apr 14, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
backend_ps: replace os.popen3 -> subprocess.Popen
  • Loading branch information
tomspur committed Apr 13, 2017
commit 79d71cc91fbcd186657f4d203385106b9e65cabe
11 changes: 7 additions & 4 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def gs_exe(self):
if gs_exe is None:
gs_exe = 'gs'

self._cached["gs_exe"] = gs_exe
self._cached["gs_exe"] = str(gs_exe)
return str(gs_exe)

@property
Expand Down Expand Up @@ -1647,9 +1647,12 @@ def get_bbox(tmpfile, bbox):
"""

gs_exe = ps_backend_helper.gs_exe
command = '%s -dBATCH -dNOPAUSE -sDEVICE=bbox "%s"' % (gs_exe, tmpfile)
command = [gs_exe, "-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox" "%s" % tmpfile]
verbose.report(command, 'debug')
stdin, stdout, stderr = os.popen3(command)
p = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True)
(stdout, stderr) = (p.stdout, p.stderr)
verbose.report(stdout.read(), 'debug-annoying')
bbox_info = stderr.read()
verbose.report(bbox_info, 'helpful')
Expand All @@ -1658,7 +1661,7 @@ def get_bbox(tmpfile, bbox):
bbox_info = bbox_found.group()
else:
raise RuntimeError('Ghostscript was not able to extract a bounding box.\
Here is the Ghostscript output:\n\n%s'% bbox_info)
Here is the Ghostscript output:\n\n%s' % bbox_info)
l, b, r, t = [float(i) for i in bbox_info.split()[-4:]]

# this is a hack to deal with the fact that ghostscript does not return the
Expand Down
0