Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sean Solari
exPAM
Commits
165c87f7
Commit
165c87f7
authored
Apr 07, 2022
by
Sean Solari
Browse files
Bug fixes in sandbox code
parent
a77bf432
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/expam/sandbox.py
View file @
165c87f7
...
...
@@ -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
(
"
\t
total
\t
used
\t
free
\t
shared
\t
buff/cache
\t
available"
)
# 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__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment