Skip to content

Instantly share code, notes, and snippets.

@jkeiser
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save jkeiser/9676173 to your computer and use it in GitHub Desktop.

Select an option

Save jkeiser/9676173 to your computer and use it in GitHub Desktop.
hang_for_reals.rb
module LXC
module Extra
def execute(&block)
r,w = IO.pipe
pid = attach do
ENV.clear
ENV['PATH'] = '/usr/bin:/bin:/usr/sbin:/sbin'
ENV['TERM'] = 'xterm-256color'
ENV['SHELL'] = '/bin/bash'
r.close
begin
out = block.call
w.write(Marshal.dump(out))
rescue Exception => e
w.write(Marshal.dump(e))
end
end
Process.wait(pid)
w.close
o = nil
if r.ready?
o = Marshal.load(r.read)
end
r.close
raise o if o.is_a?(Exception)
o
end
require 'lxc'
require 'lxc/extra'
container = LXC::Container.new('simple')
Thread.new do
puts "A"
container.execute do
puts "B"
sleep 2
puts "C"
end
puts "D"
end
puts "1"
container.execute do
puts "2"
sleep 2
puts "3"
end
puts "4"
sleep 5
1
2
3
4
A
B
C
D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment