Skip to content

Instantly share code, notes, and snippets.

@seki
Last active October 14, 2019 10:31
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 seki/0816f51977eb58327ecb01885696408b to your computer and use it in GitHub Desktop.
Save seki/0816f51977eb58327ecb01885696408b to your computer and use it in GitHub Desktop.
close on fork
require 'drb'
def test_fd
sleeper = DRbObject.new_with_uri('druby://localhost:50097')
ary = 20.times.collect {
Thread.new { sleeper.sleep(5) }
}
ary.each {|th| th.join}
system("lsof -p #{$$} | wc -l")
fork {
system("lsof -p #{$$} | wc -l")
GC.start # close on fork and GC (new one)
system("lsof -p #{$$} | wc -l")
sleeper.sleep(0.1) # close on dRuby call. (PR Fix some DRb issues #2552)
system("lsof -p #{$$} | wc -l")
}
end
test_fd
gets
test_fd
gets
require 'drb'
class Sleeper
def sleep(n)
puts "sleeping: #{n}"
Kernel.sleep(n)
end
end
DRb.start_service('druby://localhost:50097', Sleeper.new)
gets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment