[lxc-users] [python-lxc] Store attach_wait in variable
Stéphane Graber
stgraber at ubuntu.com
Wed Mar 22 17:28:39 UTC 2017
On Wed, Mar 08, 2017 at 10:08:29PM +0000, Élie Deloumeau-Prigent wrote:
> Hello everyone,
>
> Is there any way to store attach_wait output into a variable?
>
> Thanks in advance!
>
> Élie.
There is, but it's not exactly trivial. attach_wait spawns a subprocess
through fork(), so the python process memory space isn't shared and the
output therefore goes to stdout/stderr.
What we did in the past for lxc-ls which needed something like that was
have the main python process create a temporary file with
tempfile.mkstemp(), then pass the fd as an argument to the function run
by attach_wait, have the function redirect the output towards that fd
and finally having the main process rewind and read from the fd after
attach_wait returns.
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20170322/ff91584b/attachment.sig>
More information about the lxc-users
mailing list