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
beat
beat.core
Commits
e235fb01
Commit
e235fb01
authored
May 11, 2016
by
André Anjos
💬
Browse files
[prefix_cmd] Add support for a prefix command for user-code executables
parent
0878eb7b
Pipeline
#1948
failed with stage
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/core/agent.py
View file @
e235fb01
...
...
@@ -391,8 +391,8 @@ class Agent(object):
logger
.
debug
(
"Exiting processing context..."
)
def
run
(
self
,
configuration
,
timeout_in_minutes
=
0
,
daemon
=
0
):
"""Runs the algorithm code
def
run
(
self
,
configuration
,
timeout_in_minutes
=
0
,
daemon
=
0
,
prefix_cmd
=
None
):
"""Runs the
user
algorithm code
, possibly as another system user or group
Parameters:
...
...
@@ -400,15 +400,18 @@ class Agent(object):
configuration (object): A *valid*, preloaded
:py:class:`beat.core.execution.Executor` object.
timeout_in_minutes (int): The number of minutes to wait for the
user
process to execute. After this amount of time, the user process is
timeout_in_minutes (int
, Optional
): The number of minutes to wait for the
user
process to execute. After this amount of time, the user process is
killed with :py:attr:`signal.SIGKILL`. If set to zero, no timeout will
be applied.
daemon (int): If this variable is set, then we don't really start the
user process, but just kick out 0MQ server, print the command-line and
sleep for that many seconds. You're supposed to start the client by
hand then and debug it.
daemon (int, Optional): If this variable is set, then we don't really
start the user process, but just kick out 0MQ server, print the
command-line and sleep for that many seconds. You're supposed to start
the client by hand then and debug it.
prefix_cmd (list, Optional): A prefix to the command to execute allowing
you to encapsulate the user executable
"""
...
...
@@ -428,11 +431,14 @@ class Agent(object):
cmd
=
[
'sleep'
,
str
(
daemon
)]
logger
.
debug
(
"Daemon mode: sleeping for %d seconds"
,
daemon
)
if
prefix_cmd
is
not
None
:
cmd
=
prefix_cmd
+
cmd
self
.
process
=
async
.
Popen
(
cmd
=
cmd
,
virtual_memory_in_megabytes
=
self
.
virtual_memory_in_megabytes
,
max_cpu_percent
=
self
.
max_cpu_percent
,
cpulimit_path
=
self
.
cpulimit_path
cpulimit_path
=
self
.
cpulimit_path
,
)
# provide a tip on how to stop the test
...
...
beat/core/async.py
View file @
e235fb01
...
...
@@ -233,7 +233,7 @@ class Popen(gevent.subprocess.Popen):
virtual_memory_in_megabytes
=
max
(
virtual_memory_in_megabytes
,
0
)
cmd
=
_sandbox_memory
(
cmd
,
virtual_memory_in_megabytes
)
logger
.
debug
(
"Running command `%s'"
%
' '
.
join
(
cmd
))
logger
.
debug
(
"Running command `%s'"
,
' '
.
join
(
cmd
))
super
(
Popen
,
self
).
__init__
(
cmd
,
...
...
beat/core/execution.py
View file @
e235fb01
...
...
@@ -539,7 +539,7 @@ class Executor(object):
def
process
(
self
,
execute_path
=
None
,
virtual_memory_in_megabytes
=
0
,
max_cpu_percent
=
0
,
cpulimit_path
=
None
,
timeout_in_minutes
=
0
,
daemon
=
0
):
daemon
=
0
,
prefix_cmd
=
None
):
"""Executes the user algorithm code using an external program.
If ``executable`` is set, then execute the process using an external
...
...
@@ -596,6 +596,9 @@ class Executor(object):
sleep for that many seconds. You're supposed to start the client by
hand then and debug it.
prefix_cmd (list, Optional): A prefix to the command to execute allowing
you to encapsulate the user executable
Returns:
...
...
@@ -623,7 +626,7 @@ class Executor(object):
#synchronous call - always returns after a certain timeout
retval
=
runner
.
run
(
self
,
timeout_in_minutes
=
timeout_in_minutes
,
daemon
=
daemon
)
daemon
=
daemon
,
prefix_cmd
=
prefix_cmd
)
#adds I/O statistics from the current executor, if its complete already
#otherwise, it means the running process went bananas, ignore it ;-)
...
...
beat/core/test/test_execution.py
View file @
e235fb01
...
...
@@ -87,7 +87,7 @@ def load_result(executor):
return
data
def
execute
(
label
,
expected_result
):
def
execute
(
label
,
expected_result
,
prefix_cmd
=
None
):
"""Executes the full experiment, block after block, returning results. If an
error occurs, returns information about the err'd block. Otherwise, returns
``None``.
...
...
@@ -115,7 +115,7 @@ def execute(label, expected_result):
assert
executor
.
valid
,
'
\n
* %s'
%
'
\n
* '
.
join
(
executor
.
errors
)
with
executor
:
result
=
executor
.
process
()
result
=
executor
.
process
(
prefix_cmd
=
prefix_cmd
)
assert
result
assert
'status'
in
result
assert
'stdout'
in
result
...
...
@@ -171,8 +171,8 @@ def test_single_1_single():
@
slow
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_single_1_add
():
assert
execute
(
'user/user/single/1/single_add'
,
[{
'out_data'
:
43
}])
is
None
def
test_single_1_add
_prefix_cmd
():
assert
execute
(
'user/user/single/1/single_add'
,
[{
'out_data'
:
43
}]
,
[
'/usr/bin/time'
]
)
is
None
@
slow
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
...
...
André Anjos
💬
@andre.anjos
mentioned in commit
9d9538d9
·
May 11, 2016
mentioned in commit
9d9538d9
mentioned in commit 9d9538d9ef9cf3120fc5af1cbf2587bbe7e11d68
Toggle commit list
Write
Preview
Supports
Markdown
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