Ignore:
Timestamp:
21 Aug 2015, 13:44:03 (9 years ago)
Author:
uli
Message:

Add get_mem_info().

We return memory infos if psutil is locally available.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/scripts.py

    r13204 r13205  
    127127
    128128
     129def get_mem_info():
     130    """Get current memory info.
     131
     132    This works only, if `psutil` is installed locally (in virtualenv).
     133    Otherwise we return `None`.
     134    """
     135    try:
     136        # late import. We do not want to make it a waeup.uniben dependency.
     137        import psutil
     138    except ImportError:
     139        return
     140    proc = psutil.Process(os.getpid())
     141    return proc.get_memory_info().rss
     142
     143
    129144def export_part(container, part_num, start, end, path):
    130     import psutil  # late import. Don't want to make it waeup.uniben req.
    131     PROC = psutil.Process(os.getpid())
    132145    gc.collect()
    133     mem1 = PROC.get_memory_info().rss
     146    mem1 = get_mem_info()
    134147    print("  Export %s-%s to %s (mem: %s)" % (start, end, path, mem1))
    135148    tp1 = time.time()
     
    137150    exporter.export(get_all_students(container, start, end), path)
    138151    tp2 = time.time()
    139     mem2 = PROC.get_memory_info().rss
     152    mem2 = get_mem_info()
    140153    print("  Done (%s secs, mem: %s)" % (tp2 - tp1, mem2))
    141154
Note: See TracChangeset for help on using the changeset viewer.