Commit 165c87f7 authored by Sean Solari's avatar Sean Solari
Browse files

Bug fixes in sandbox code

parent a77bf432
......@@ -11,7 +11,7 @@ import time
def check_free_command():
err = subprocess.run(['free', '-h'], capture_output=True, shell=True).stderr
err = subprocess.run(['free', '--mega'], capture_output=True, shell=True).stderr
if err:
return False
......@@ -66,6 +66,10 @@ def sandbox(logging_name, mem_limit, interval):
logger = logging.getLogger(logging_name)
logger.info("\ttotal\tused\tfree\tshared\tbuff/cache\tavailable")
# Initial log for starting memory usage.
mem_info = subprocess.run(['free', '--mega'], capture_output=True).stdout.decode()
logger.info("Initial...%s" % "\t".join(re.findall(r"[^\s]+", mem_info)[6:13]))
# Start new child process.
ctx = mp.get_context('fork')
......@@ -76,7 +80,7 @@ def sandbox(logging_name, mem_limit, interval):
while p.is_alive():
# Log memory usage.
mem_info = subprocess.run(['free', '-h'], capture_output=True).stdout.decode()
mem_info = subprocess.run(['free', '--mega'], capture_output=True).stdout.decode()
logger.info("\t".join(re.findall(r"[^\s]+", mem_info)[6:13]))
time.sleep(interval)
......@@ -118,8 +122,8 @@ def parse():
return mem_limit, args.interval, args.out, args.command
def sandbox_command(data):
mem_limit, interval, out_file, cmd = parse(data)
def sandbox_command():
mem_limit, interval, out_file, cmd = parse()
if mem_limit is None:
soft, hard = resource.getrlimit(resource.RLIMIT_RSS)
......@@ -149,13 +153,11 @@ def sandbox_command(data):
def main():
print(parse())
if not check_free_command():
print("Must run on Linux system (or have `free` command available).")
sys.exit(1)
# sandbox_command()
sandbox_command()
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment