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

Skip to content

Commit c8c5c32

Browse files
committed
cbook.report_memory: restore compatibility with earlier subprocess versions
svn path=/trunk/matplotlib/; revision=8958
1 parent cc95248 commit c8c5c32

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lib/matplotlib/cbook.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ def restrict_dict(d, keys):
12331233

12341234
def report_memory(i=0): # argument may go away
12351235
'return the memory consumed by process'
1236-
from subprocess import Popen, PIPE, check_output
1236+
from subprocess import Popen, PIPE
12371237
pid = os.getpid()
12381238
if sys.platform=='sunos5':
12391239
a2 = Popen('ps -p %d -o osz' % pid, shell=True,
@@ -1248,7 +1248,13 @@ def report_memory(i=0): # argument may go away
12481248
stdout=PIPE).stdout.readlines()
12491249
mem = int(a2[1].split()[0])
12501250
elif sys.platform.startswith('win'):
1251-
a2 = check_output(["tasklist", "/nh", "/fi", "pid eq %d" % pid])
1251+
try:
1252+
a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
1253+
stdout=PIPE).stdout.read()
1254+
except OSError:
1255+
raise NotImplementedError(
1256+
"report_memory works on Windows only if "
1257+
"the 'tasklist' program is found")
12521258
mem = int(a2.strip().split()[-2].replace(',',''))
12531259
else:
12541260
raise NotImplementedError(

0 commit comments

Comments
 (0)