mirror of
https://github.com/ARM-software/devlib.git
synced 2025-03-04 01:07:51 +00:00
Merge pull request #143 from valschneider/invoke_bg
Add option to run target.invoke() in the background
This commit is contained in:
commit
8f63914b85
@ -351,6 +351,38 @@ class Target(object):
|
||||
command = 'cd {} && {}'.format(in_directory, command)
|
||||
return self.execute(command, as_root=as_root, timeout=timeout)
|
||||
|
||||
def background_invoke(self, binary, args=None, in_directory=None,
|
||||
on_cpus=None, as_root=False):
|
||||
"""
|
||||
Executes the specified binary as a background task under the
|
||||
specified conditions.
|
||||
|
||||
:binary: binary to execute. Must be present and executable on the device.
|
||||
:args: arguments to be passed to the binary. The can be either a list or
|
||||
a string.
|
||||
:in_directory: execute the binary in the specified directory. This must
|
||||
be an absolute path.
|
||||
:on_cpus: taskset the binary to these CPUs. This may be a single ``int`` (in which
|
||||
case, it will be interpreted as the mask), a list of ``ints``, in which
|
||||
case this will be interpreted as the list of cpus, or string, which
|
||||
will be interpreted as a comma-separated list of cpu ranges, e.g.
|
||||
``"0,4-7"``.
|
||||
:as_root: Specify whether the command should be run as root
|
||||
|
||||
:returns: the subprocess instance handling that command
|
||||
"""
|
||||
command = binary
|
||||
if args:
|
||||
if isiterable(args):
|
||||
args = ' '.join(args)
|
||||
command = '{} {}'.format(command, args)
|
||||
if on_cpus:
|
||||
on_cpus = bitmask(on_cpus)
|
||||
command = '{} taskset 0x{:x} {}'.format(self.busybox, on_cpus, command)
|
||||
if in_directory:
|
||||
command = 'cd {} && {}'.format(in_directory, command)
|
||||
return self.background(command, as_root=as_root)
|
||||
|
||||
def kick_off(self, command, as_root=False):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -265,6 +265,24 @@ Target
|
||||
:param timeout: If this is specified and invocation does not terminate within this number
|
||||
of seconds, an exception will be raised.
|
||||
|
||||
.. method:: Target.background_invoke(binary [, args [, in_directory [, on_cpus [, as_root ]]]])
|
||||
|
||||
Execute the specified binary on target (must already be installed) as a background
|
||||
task, under the specified conditions and return the :class:`subprocess.Popen`
|
||||
instance for the command.
|
||||
|
||||
:param binary: binary to execute. Must be present and executable on the device.
|
||||
:param args: arguments to be passed to the binary. The can be either a list or
|
||||
a string.
|
||||
:param in_directory: execute the binary in the specified directory. This must
|
||||
be an absolute path.
|
||||
:param on_cpus: taskset the binary to these CPUs. This may be a single ``int`` (in which
|
||||
case, it will be interpreted as the mask), a list of ``ints``, in which
|
||||
case this will be interpreted as the list of cpus, or string, which
|
||||
will be interpreted as a comma-separated list of cpu ranges, e.g.
|
||||
``"0,4-7"``.
|
||||
:param as_root: Specify whether the command should be run as root
|
||||
|
||||
.. method:: Target.kick_off(command [, as_root])
|
||||
|
||||
Kick off the specified command on the target and return immediately. Unlike
|
||||
|
Loading…
x
Reference in New Issue
Block a user