Skip to content

Instantly share code, notes, and snippets.

@cookrn

cookrn/client.rb

Created Dec 15, 2015
Embed
What would you like to do?
A tiny, standard-library only example of attaching to a running process over the network for inspection
#!/usr/bin/env ruby
require 'drb'
require 'irb'
DRb.start_service
$context = DRbObject.new_with_uri('druby://localhost:9876')
IRB.start
#!/usr/bin/env ruby
require 'drb'
require 'thread'
require 'webrick'
$i = 0
$main = self
$running = false
$semaphore = Mutex.new
module Context
extend self
def i
$i
end
end
Thread.new do
server = WEBrick::HTTPServer.new(Port: 9001)
server.mount_proc '/' do |req, res|
$semaphore.synchronize do
if !$running
$running = true
Thread.new { DRb.start_service('druby://localhost:9876', Context) }
end
end
end
begin
server.start
ensure
server.shutdown
end
end
loop do
$stderr.puts($i)
$stderr.puts($running.inspect)
$i = $i + 1
sleep(rand($i))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment