Last active
August 29, 2015 13:57
-
-
Save jkeiser/9676173 to your computer and use it in GitHub Desktop.
hang_for_reals.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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