`lxc launch ...` hangs if executed from Python under Pycharm

Ok.
I know.
This is very weird and very likely to have nothing to do with lxc/lxd at all.
I am asking here exactly because it is very strange and insight from knowledgeable people could make the difference.

I am trying to write a python script to automatize container handling.
It generally works quite well but there’s ONE command that hangs completely if/when used under PyCharm (it works perfectly fine if run from the command line).

this minimal example:

import subprocess

image = 'images:ubuntu/bionic'
name = 'name'

r = subprocess.run(['lxc', 'launch', image, name])
print(r)

never prints anything (if and only if run under PyCharm!) and the container is not created at all.

What kind of PyCharm bug could justify such a behavior?

Other commands (e.g.: lxc list, lxc exec ..., lxc stop ... and even lxc delete ...) seem to work without problems; What’s so special in lxc launch ...??

Many Thanks in Advance

Can confirm what you are saying. Spent an hour trying to fix this but go nowhere!

Interestingly the command never makes it to the point where it hits the API (you can run lxc monitor --debug --pretty in another shell to confirm this).

lxc launch and lxc init consume YAML from stdin, I suspect python makes it look like there’s data to consume on stdin making the command hang.

Try with stdin=None or whatever the python syntax is for that.

Sorry for the late answer.

stdin=None is the default (subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs).

Can I provide a “fake” YAML to test your suspect?
If so what should I give?

Thanks in Advance!

You don’t need to provide any yaml, just close stdin.

As always @tomp coming through :star:

The below works

import subprocess
r = subprocess.Popen(['lxc', 'launch', 'ubuntu:', 'c1'], stdin=subprocess.PIPE)
r.communicate(input=b"")
1 Like