Return available memory in bytes, or None if unknown.
()
| 2452 | |
| 2453 | |
| 2454 | def _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 | |
| 2478 | def _no_tracing(func): |
no test coverage detected