MCPcopy Create free account
hub / github.com/numpy/numpy / _get_mem_available

Function _get_mem_available

numpy/testing/_private/utils.py:2454–2475  ·  view source on GitHub ↗

Return available memory in bytes, or None if unknown.

()

Source from the content-addressed store, hash-verified

2452
2453
2454def _get_mem_available():
2455 """Return available memory in bytes, or None if unknown."""
2456 try:
2457 import psutil
2458 return psutil.virtual_memory().available
2459 except (ImportError, AttributeError):
2460 pass
2461
2462 if sys.platform.startswith('linux'):
2463 info = {}
2464 with open('/proc/meminfo') as f:
2465 for line in f:
2466 p = line.split()
2467 info[p[0].strip(':').lower()] = int(p[1]) * 1024
2468
2469 if 'memavailable' in info:
2470 # Linux >= 3.14
2471 return info['memavailable']
2472 else:
2473 return info['memfree'] + info['cached']
2474
2475 return None
2476
2477
2478def _no_tracing(func):

Callers 1

check_free_memoryFunction · 0.85

Calls 5

openFunction · 0.85
startswithMethod · 0.80
lowerMethod · 0.80
stripMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected