[lxc-devel] attach_wait and threads

Stéphane Graber stgraber at ubuntu.com
Mon Jun 30 21:12:37 UTC 2014


On Mon, Jun 30, 2014 at 06:28:41PM +0200, Dorian Eikenberg wrote:
> Hi there,
> 
> I am currently working on a python script that makes use of the python-lxc library (lxc version is the current git version). I had a timer running that would stop the container if the attach_wait method took to long to return. However the event was not triggered before the attach_wait method returned no matter how long this took.
> As far as I know the problem can be fixed by making the Container_attach_and_possibly_wait function in python-lxc/lxc.c GIL-aware. Tested this with the script provided below and it worked fine for me.
> Here is a minimal python script which should be able to reproduce the problem given a running container "test":
>  
> import lxc
> import threading
> 
> 
> def event():
>  print("Hello")
> 
> 
> def main():
>  container = lxc.Container("test")
>  timer = threading.Timer(2, event)
>  timer.start()
>  container.attach_wait(lxc.attach_run_command, ["/bin/sleep", "7"])
>  print("all done")
> 
> if __name__ == "__main__":
>  main()
>  
> On my system both prints were executed after approx 7 secs.
> After applying the following changes to lcx.c the "Hello" string was printed correctly approx 5 secs ahead of "all done":
>  
> in Container_attach_and_possibly_wait starting at line 583:
> 
> if (wait) {
>  Py_BEGIN_ALLOW_THREADS
>  ret = lxc_wait_for_pid_status(pid);
>  Py_END_ALLOW_THREADS
>  (...)
>  
> I hope this was helpful.
>  
> Regards,
>  
> Dorian Eikenberg

Hi!

My knowledge of python threading is somewhat limited but this seems
reasonable, would you be able to send us a proper patch implementing
this (including the required Signed-off-by line)?

Thanks!


-- 
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: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140630/a1c1f3fb/attachment.sig>


More information about the lxc-devel mailing list