Return available memory in bytes, or None if unknown.
()
| 2751 | |
| 2752 | |
| 2753 | def _get_mem_available(): |
| 2754 | """Return available memory in bytes, or None if unknown.""" |
| 2755 | try: |
| 2756 | import psutil |
| 2757 | return psutil.virtual_memory().available |
| 2758 | except (ImportError, AttributeError): |
| 2759 | pass |
| 2760 | |
| 2761 | if sys.platform.startswith('linux'): |
| 2762 | info = {} |
| 2763 | with open('/proc/meminfo') as f: |
| 2764 | for line in f: |
| 2765 | p = line.split() |
| 2766 | info[p[0].strip(':').lower()] = int(p[1]) * 1024 |
| 2767 | |
| 2768 | if 'memavailable' in info: |
| 2769 | # Linux >= 3.14 |
| 2770 | return info['memavailable'] |
| 2771 | else: |
| 2772 | return info['memfree'] + info['cached'] |
| 2773 | |
| 2774 | return None |
| 2775 | |
| 2776 | |
| 2777 | def _no_tracing(func): |
no test coverage detected
searching dependent graphs…