Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b29c93c

Browse files
committed
subprocess_fixed: Gracefully handle platforms without subprocess.Popen.
If subprocess.Popen is missing (for example, on Google App Engine), replaces it with a dummy version that raises OSError. In these environments, calls to subprocess will be handled properly as if the called app could not be found, instead of raising AttributeError.
1 parent 52c075f commit b29c93c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/matplotlib/subprocess_fixed.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
work-arounds:
44
- Provides the check_output function (which subprocess only provides from Python
55
2.7 onwards).
6+
- Provides a stub implementation of subprocess members on Google App Engine
7+
(which are missing in subprocess).
68
79
Instead of importing subprocess, other modules should use this as follows:
810
@@ -17,9 +19,19 @@
1719

1820
__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output']
1921

20-
Popen = subprocess.Popen
21-
PIPE = subprocess.PIPE
22-
STDOUT = subprocess.STDOUT
22+
23+
if hasattr(subprocess, 'Popen'):
24+
Popen = subprocess.Popen
25+
# Assume that it also has the other constants.
26+
PIPE = subprocess.PIPE
27+
STDOUT = subprocess.STDOUT
28+
else:
29+
# In restricted environments (such as Google App Engine), these are
30+
# non-existent. Replace them with dummy versions that always raise OSError.
31+
def Popen(*args, **kwargs):
32+
raise OSError("subprocess.Popen is not supported")
33+
PIPE = -1
34+
STDOUT = -2
2335

2436

2537
def _check_output(*popenargs, **kwargs):

0 commit comments

Comments
 (0)