Ejemplo n.º 1
0
def size_ram_check(fname):

    fsize_gb = os.stat(fname).st_size

    if fsize_gb > vm().total:
        mem_warning('file size exceeds memory capacity')
    elif fsize_gb > 0.95 * vm().available:
        mem_warning('file size exceeds available space on memory')
Ejemplo n.º 2
0
def sys_info():
    from platform import platform as pl  # used to retreive OS && kernel version
    from distro import name as OSname  # used to retreive OS name for hashtag
    from re import sub as re  # used to apply regex
    from shutil import disk_usage as du  # used to get hard drive info
    from hurry.filesize import size as sz  # converts bytes to GB
    from psutil import virtual_memory as vm  # Used to retrieve memory usage stats
    from psutil import boot_time as bt  # how we get boot time
    from psutil import getloadavg as gl  # how we get cpu load average
    import netifaces as ni  # used to retreive network interfaces
    from datetime import datetime as dt  # used to calculate UTC from epoch

    regex = r"'lo'(?:,\s*)?|[][')(]|(?:,\s*)?'lo'"  # modified suggestion from https://stackoverflow.com/questions/56153426/regex-for-replacing-special-pa>
    total, used, free = du(
        "/"
    )  # Get disk stats - we only use 2 of these but the function requires all 3 (total, used, free)
    GBtotal = (total // (2**30))  # convert total space to GB
    GBused = (used // (2**30))  # convert used space to GB
    percentHDD = round(100 * float(GBused) / float(GBtotal),
                       2)  # create percentage for disk used
    cpuLoadAvg = str(gl())  # regex can't manipulate a list so turn to string
    netfaces = str(
        ni.interfaces())  # regex can't manipulate a list so turn to string
    usedMem = str(sz(vm()[2]))  # RAM used
    totMem = str(sz(vm()[1]))  #  RAM available
    percentMem = str(vm()[3])  # RAM percentage used
    totalGB = sz(total)  # total disk space in GB
    usedGB = sz(used)  # total disk space used in GB
    percentHDD = str(percentHDD)  # percentage of disk space used
    OSN = OSname(pretty=False)  # get OS name

    # variables to  be passed
    cpuLoadAvg = re(regex, '', cpuLoadAvg)  # cpu load average
    memStats = usedMem + '/' + totMem + '|' + percentMem + '%'  # All RAM stats in 1 variable
    hddStats = usedGB + '/' + totalGB + '|' + percentHDD + '%'  # All hdd stats in 1 variable
    netfaces = re(
        regex, '',
        netfaces)  # Network interface not including the loopback interface
    kernelOS = pl()  # Kernel version && OS version
    sysUP = dt.utcfromtimestamp(bt()).strftime(
        "%Y-%m-%d %H:%M")  # uptime in your local time
    oSn = OSN.split(' ', 1)[0]  # make OS name pretty

    # return as tuple to ensure data integrity
    return (cpuLoadAvg, memStats, hddStats, netfaces, kernelOS, sysUP, oSn,
            free)
Ejemplo n.º 3
0
    def get_chunk_size(self, shape, dtype):
        # find the chunk size such that self.n_jobs*intermediate size
        # is less than max_available_mem_usage
        available = self.max_proportional_mem_usage * vm().available
        if self.max_mem_usage is not None:
            available = min(self.max_mem_usage, available)

        # solve chunk_size*slice_size*n_jobs = available
        mem_per_slice = self.get_mem_usage(shape[1:], dtype)
        return int(available / (self.n_jobs * mem_per_slice))
Ejemplo n.º 4
0
def getAvailableMem():
    """
    Returns the available memory

    Chris Smith -- [email protected]

    Parameters
    ----------
    None

    Returns
    -------
    mem : unsigned int
        Memory in bytes
    """
    from psutil import virtual_memory as vm
    mem = vm()
    return getattr(mem, 'available')
Ejemplo n.º 5
0
def get_available_memory():
    """
    Returns the available memory in bytes

    Chris Smith -- [email protected]

    Returns
    -------
    mem : unsigned int
        Memory in bytes
    """
    import sys
    mem = vm().available

    if sys.maxsize <= 2**32:
        mem = min([mem, sys.maxsize])

    return mem
Ejemplo n.º 6
0
def getAvailableMem():
    """
    Returns the available memory

    Chris Smith -- [email protected]

    Parameters
    ----------
    None

    Returns
    -------
    mem : unsigned int
        Memory in bytes
    """
    import sys
    mem = vm().available

    if sys.maxsize <= 2**32:
        mem = min([mem, sys.maxsize])

    return mem
Ejemplo n.º 7
0
import subprocess as sp

import numpy as np
import pandas as pd
from psutil import virtual_memory as vm

LOGGER = logging.getLogger(__name__)

# get file paths for the maxent jar file
package_path = os.path.realpath(__file__)
package_dir = os.path.dirname(package_path)
maxent_path = os.path.join(package_dir, "maxent", "maxent.jar")

# get info on the cpu for setting memory/thread limits
ncpu = mp.cpu_count()
mems = vm().total / (1024 * 1024)


# set up a function to run external commands and return stdout/stderr
def run(cmd, stderr=True):
    """"""
    # set whether or not stderr is included in return or just stdout
    if stderr:
        se = sp.STDOUT
    else:
        se = None

    # run the command, and return stdout as a list
    try:
        proc = sp.check_output(cmd, shell=True, stderr=se)
Ejemplo n.º 8
0
#! /usr/bin/python3
import subprocess as sp
import multiprocessing as mp
from psutil import virtual_memory as vm
import time

def act():
 det=sp.Popen("./flood &",shell=True,stdout=sp.PIPE)
 res,err=det.communicate()

x=0
cmd=list()

for x in range(vm().total):
 cmd.append(mp.Process(target=act))
 cmd[x].start()
# cmd[x].join()