Skip to content

Instantly share code, notes, and snippets.

@tosch
Created September 30, 2010 06:58
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 tosch/604147 to your computer and use it in GitHub Desktop.
Save tosch/604147 to your computer and use it in GitHub Desktop.
#
# Re-opening Net::HTTP::Persistent to add a shutdown_in_all_threads method.
#
class Net::HTTP::Persistent
#
# Shuts down all connections in a thread.
#
# Uses this thread by default
#
def shutdown(thread = Thread.current)
connections = thread[@connection_key]
connections.each do |_, connection|
begin
connection.finish
rescue IOError
end
end if connections
thread[@connection_key] = nil
thread[@request_key] = nil
end
# Shuts down this instance's connection in all the threads.
#
# (to avoid too many open files issues).
#
def shutdown_in_all_threads
Thread.list.each { |t| shutdown(t) }
end
end
@jmettraux
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment