@@ -1241,29 +1241,20 @@ class _MemoryWatchdog:
12411241 """
12421242
12431243 def __init__ (self ):
1244- self .procfile = '/proc/{pid}/statm' .format (pid = os .getpid ())
12451244 self .started = False
12461245
12471246 def start (self ):
1248- try :
1249- f = open (self .procfile , 'r' )
1250- except OSError as e :
1251- logging .getLogger (__name__ ).warning ('/proc not available for stats: %s' , e , exc_info = e )
1252- sys .stderr .flush ()
1253- return
1254-
12551247 import subprocess
1256- with f :
1257- watchdog_script = findfile ("memory_watchdog.py" )
1258- self .mem_watchdog = subprocess .Popen ([sys .executable , watchdog_script ],
1259- stdin = f ,
1260- stderr = subprocess .DEVNULL )
1248+ watchdog_script = findfile ("memory_watchdog.py" )
1249+ cmd = [sys .executable , watchdog_script , str (os .getpid ())]
1250+ self .mem_watchdog = subprocess .Popen (cmd )
12611251 self .started = True
12621252
12631253 def stop (self ):
1264- if self .started :
1265- self .mem_watchdog .terminate ()
1266- self .mem_watchdog .wait ()
1254+ if not self .started :
1255+ return
1256+ self .mem_watchdog .terminate ()
1257+ self .mem_watchdog .wait ()
12671258
12681259
12691260def bigmemtest (size , memuse , dry_run = True ):
@@ -1296,8 +1287,8 @@ def wrapper(self):
12961287
12971288 if real_max_memuse and verbose :
12981289 print ()
1299- print ( " ... expected peak memory use: {peak:.1f}G"
1300- . format ( peak = size * memuse / ( 1024 ** 3 )) )
1290+ peak = ( size * memuse ) / ( 1024 ** 3 )
1291+ print ( f" ... expected peak memory use: { peak :.1f } GiB" )
13011292 watchdog = _MemoryWatchdog ()
13021293 watchdog .start ()
13031294 else :
0 commit comments