@@ -1233,7 +1233,7 @@ def restrict_dict(d, keys):
12331233
12341234def 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