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 ...@@ -11,7 +11,7 @@ import time
def check_free_command(): 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: if err:
return False return False
...@@ -66,6 +66,10 @@ def sandbox(logging_name, mem_limit, interval): ...@@ -66,6 +66,10 @@ def sandbox(logging_name, mem_limit, interval):
logger = logging.getLogger(logging_name) logger = logging.getLogger(logging_name)
logger.info("\ttotal\tused\tfree\tshared\tbuff/cache\tavailable") 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. # Start new child process.
ctx = mp.get_context('fork') ctx = mp.get_context('fork')
...@@ -76,7 +80,7 @@ def sandbox(logging_name, mem_limit, interval): ...@@ -76,7 +80,7 @@ def sandbox(logging_name, mem_limit, interval):
while p.is_alive(): while p.is_alive():
# Log memory usage. # 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])) logger.info("\t".join(re.findall(r"[^\s]+", mem_info)[6:13]))
time.sleep(interval) time.sleep(interval)
...@@ -118,8 +122,8 @@ def parse(): ...@@ -118,8 +122,8 @@ def parse():
return mem_limit, args.interval, args.out, args.command return mem_limit, args.interval, args.out, args.command
def sandbox_command(data): def sandbox_command():
mem_limit, interval, out_file, cmd = parse(data) mem_limit, interval, out_file, cmd = parse()
if mem_limit is None: if mem_limit is None:
soft, hard = resource.getrlimit(resource.RLIMIT_RSS) soft, hard = resource.getrlimit(resource.RLIMIT_RSS)
...@@ -149,13 +153,11 @@ def sandbox_command(data): ...@@ -149,13 +153,11 @@ def sandbox_command(data):
def main(): def main():
print(parse())
if not check_free_command(): if not check_free_command():
print("Must run on Linux system (or have `free` command available).") print("Must run on Linux system (or have `free` command available).")
sys.exit(1) sys.exit(1)
# sandbox_command() sandbox_command()
if __name__ == '__main__': 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