Skip to content

Instantly share code, notes, and snippets.

@larryprice
Last active August 17, 2016 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larryprice/f562f838ff84929c1619978a6404b8b6 to your computer and use it in GitHub Desktop.
Save larryprice/f562f838ff84929c1619978a6404b8b6 to your computer and use it in GitHub Desktop.
Light script to demonstrate lxc.attach_wait hoarding stdin even after it's finished
#!/usr/bin/env python3
import lxc
import time
import os
CONTAINER_NAME='xenial'
CONTAINER_PATH='%s/.cache/libertine-container' % os.environ["HOME"]
def lxc_work():
container = lxc.Container(CONTAINER_NAME, CONTAINER_PATH)
container.start()
container.attach_wait(lxc.attach_run_command, ['ls'])
def sleep_work():
time.sleep(5)
print("Ctrl+C will attempt to stop the script during the next ~5 seconds")
sleep_work()
print("Running lxc command 'ls' in container '%s', please wait..." % CONTAINER_NAME)
lxc_work()
print("Ctrl+C should attempt to stop the script in the next ~5 seconds, but doesn't")
sleep_work()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment