Skip to content

Commit 2375269

Browse files
authored
Merge pull request #1345 from mathics/system-memory-redux
Go over $SystemMemory and MemoryAvailable[]
2 parents 369f6d1 + 7bedfba commit 2375269

3 files changed

Lines changed: 15 additions & 19 deletions

File tree

CHANGES.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ CHANGES
55
2.1.1
66
-----
77

8-
New builtins
9-
++++++++++++
8+
New variables and builtins
9+
++++++++++++++++++++++++++
1010

1111
* ``Arg``
1212
* ``Dispatch``
1313
* ``FullSimplify``
1414
* ``LetterNumber`` #1298. The ``alphabet`` parameter supports only a minimal number of languages.
15+
* ``MemoryAvailable``
16+
* ``MemoryInUse``
1517
* ``Nand`` and ``Nor`` logical functions.
1618
* ``Series``, ``O`` and ``SeriesData``
1719
* ``StringReverse``
20+
* ``$SystemMemory``
1821
* Add all of the named colors, e.g. ``Brown`` or ``LighterMagenta``.
1922

2023

@@ -28,7 +31,7 @@ Enhancements
2831
* ``D`` and ``Derivative`` improvements.
2932
* ``FileNames`` returns a sorted list (#1250).
3033
* ``FindRoot`` now receives several optional parameters like ``Method`` and ``MaxIterations``.
31-
* ``FixedPoint`` now supports the ``SameTest`` option.
34+
* ``FixedPoint`` now supports the ``SameTest`` option.
3235
* ``Prime`` and ``PrimePi`` now accept a list parameter and have the ``NumericFunction`` attribute.
3336
* ``ReplaceRepeated`` and ``FixedPoint`` now supports the ``MaxIteration`` option (#1260).
3437
* ``Simplify`` performs a more sophisticated set of simplifications.
@@ -38,7 +41,7 @@ Enhancements
3841
* ``ToString`` accepts an optional *form* parameter.
3942
* ``ToExpression`` handles multi-line string input
4043
* The implementation of Streams was redone.
41-
44+
4245

4346

4447
Bug fixes
@@ -54,7 +57,7 @@ Internal changes
5457
----------------
5558

5659
* doctest accepts the option `-d` to show how long it takes to parse, evaluate and compare each individual test.
57-
60+
5861

5962
2.1.0
6063
-----

mathics/builtin/system.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import platform
11+
import psutil
1112
import sys
1213
import re
1314
import subprocess
@@ -472,13 +473,8 @@ class SystemMemory(Predefined):
472473
name = "$SystemMemory"
473474

474475
def evaluate(self, evaluation) -> Integer:
475-
try:
476-
import psutil
477-
totalmem = psutil.virtual_memory().total
478-
return Integer(total)
479-
except:
480-
return String(SymbolFailed)
481-
476+
totalmem = psutil.virtual_memory().total
477+
return Integer(totalmem)
482478

483479
class MemoryAvailable(Builtin):
484480
"""
@@ -491,14 +487,10 @@ class MemoryAvailable(Builtin):
491487
= ...
492488
"""
493489

494-
def apply_0(self, evaluation) -> Integer:
490+
def apply(self, evaluation) -> Integer:
495491
"""MemoryAvailable[]"""
496-
try:
497-
import psutil
498-
totalmem = psutil.virtual_memory().available
499-
return Integer(total)
500-
except:
501-
return String(SymbolFailed)
492+
totalmem = psutil.virtual_memory().available
493+
return Integer(totalmem)
502494

503495

504496
class MemoryInUse(Builtin):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def read(*rnames):
9797
"palettable",
9898
"pint",
9999
"python-dateutil",
100+
"psutil", # for $SystemMemory
100101
"llvmlite",
101102
"requests",
102103
"scikit-image",

0 commit comments

Comments
 (0)