Created
September 30, 2010 06:58
-
-
Save tosch/604147 to your computer and use it in GitHub Desktop.
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
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1