|
8 | 8 |
|
9 | 9 | import os |
10 | 10 | import platform |
11 | | -import psutil |
12 | 11 | import sys |
13 | 12 | import re |
14 | 13 | import subprocess |
|
29 | 28 | from mathics import version_string |
30 | 29 | from mathics.builtin.strings import to_regex |
31 | 30 |
|
| 31 | +try: |
| 32 | + import psutil |
| 33 | +except: |
| 34 | + have_psutil = False |
| 35 | +else: |
| 36 | + have_psutil = True |
| 37 | + |
32 | 38 |
|
33 | 39 | class Aborted(Predefined): |
34 | 40 | """ |
@@ -459,42 +465,43 @@ def evaluate(self, evaluation) -> Real: |
459 | 465 | return Real(self.value) |
460 | 466 |
|
461 | 467 |
|
462 | | -class SystemMemory(Predefined): |
463 | | - """ |
464 | | - <dl> |
465 | | - <dt>'$SystemMemory' |
466 | | - <dd>Returns the total amount of physical memory. |
467 | | - </dl> |
| 468 | +if have_psutil: |
| 469 | + class SystemMemory(Predefined): |
| 470 | + """ |
| 471 | + <dl> |
| 472 | + <dt>'$SystemMemory' |
| 473 | + <dd>Returns the total amount of physical memory. |
| 474 | + </dl> |
468 | 475 |
|
469 | | - >> $SystemMemory |
470 | | - = ... |
471 | | - """ |
| 476 | + >> $SystemMemory |
| 477 | + = ... |
| 478 | + """ |
472 | 479 |
|
473 | | - name = "$SystemMemory" |
| 480 | + name = "$SystemMemory" |
474 | 481 |
|
475 | | - def evaluate(self, evaluation) -> Integer: |
476 | | - totalmem = psutil.virtual_memory().total |
477 | | - return Integer(totalmem) |
| 482 | + def evaluate(self, evaluation) -> Integer: |
| 483 | + totalmem = psutil.virtual_memory().total |
| 484 | + return Integer(totalmem) |
478 | 485 |
|
479 | | -class MemoryAvailable(Builtin): |
480 | | - """ |
481 | | - <dl> |
482 | | - <dt>'MemoryAvailable' |
483 | | - <dd>Returns the amount of the available physical memory. |
484 | | - </dl> |
| 486 | + class MemoryAvailable(Builtin): |
| 487 | + """ |
| 488 | + <dl> |
| 489 | + <dt>'MemoryAvailable' |
| 490 | + <dd>Returns the amount of the available physical memory. |
| 491 | + </dl> |
485 | 492 |
|
486 | | - >> MemoryAvailable[] |
487 | | - = ... |
| 493 | + >> MemoryAvailable[] |
| 494 | + = ... |
488 | 495 |
|
489 | | - The relationship between $SystemMemory, MemoryAvailable, and MemoryInUse: |
490 | | - >> $SystemMemory > MemoryAvailable[] > MemoryInUse[] |
491 | | - = True |
492 | | - """ |
| 496 | + The relationship between $SystemMemory, MemoryAvailable, and MemoryInUse: |
| 497 | + >> $SystemMemory > MemoryAvailable[] > MemoryInUse[] |
| 498 | + = True |
| 499 | + """ |
493 | 500 |
|
494 | | - def apply(self, evaluation) -> Integer: |
495 | | - """MemoryAvailable[]""" |
496 | | - totalmem = psutil.virtual_memory().available |
497 | | - return Integer(totalmem) |
| 501 | + def apply(self, evaluation) -> Integer: |
| 502 | + """MemoryAvailable[]""" |
| 503 | + totalmem = psutil.virtual_memory().available |
| 504 | + return Integer(totalmem) |
498 | 505 |
|
499 | 506 |
|
500 | 507 | class MemoryInUse(Builtin): |
|
0 commit comments