Module Expr Str Import alias Import alias Import alias Import alias Import alias Assign NameStore Call AttributeLoad NameLoad attr ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam NameParam defaults Num Num body Import alias Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr Dict Assign AttributeStore NameLoad attr Num Assign AttributeStore NameLoad attr Num decorator_list FunctionDef arguments args NameParam NameParam defaults body TryExcept body Expr Call AttributeLoad NameLoad attr handlers ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Delete SubscriptDel AttributeLoad NameLoad attr Index NameLoad TryExcept body Expr Call AttributeLoad NameLoad attr Str Call NameLoad Call NameLoad NameLoad Call NameLoad Call AttributeLoad NameLoad attr handlers ExceptHandler body Pass Return NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body TryExcept body Expr Call AttributeLoad NameLoad attr Str Call NameLoad Call NameLoad NameLoad Call NameLoad Call AttributeLoad NameLoad attr handlers ExceptHandler body Pass TryExcept body If SubscriptLoad Call AttributeLoad NameLoad attr ListLoad NameLoad ListLoad ListLoad Num Index Num body Expr Call AttributeLoad NameLoad attr NameLoad Return handlers ExceptHandler body Return Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad ListLoad AugAssignAdd AttributeStore NameLoad attr Num Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If CompareLtE AttributeLoad NameLoad attr NameLoad body Return Assign NameStore BinOpSub AttributeLoad NameLoad attr NameLoad Assign NameStore SubscriptLoad Call NameLoad ListComp TupleLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Slice UnaryOpUSub NameLoad AugAssignSub AttributeStore NameLoad attr NameLoad Return ListComp Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad ListLoad If CompareLtE Call NameLoad NameLoad NameLoad body Return Assign NameStore BinOpSub Call NameLoad NameLoad NameLoad Assign NameStore SubscriptLoad Call NameLoad ListComp TupleLoad SubscriptLoad AttributeLoad NameLoad attr Index NameLoad NameLoad comprehension NameStore NameLoad Slice UnaryOpUSub NameLoad AugAssignSub AttributeStore NameLoad attr NameLoad Return ListComp Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Index Num comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Call AttributeLoad SubscriptLoad AttributeLoad NameLoad attr Index Call AttributeLoad NameLoad attr attr NameLoad Delete SubscriptDel AttributeLoad NameLoad attr Index NameLoad Return Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return Call NameLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad TupleLoad decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore ListLoad Assign AttributeStore NameLoad attr Num For NameStore AttributeLoad NameLoad attr body Assign NameStore ListLoad For NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad body If CompareGt BinOpSub Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Num AttributeLoad NameLoad attr body TryExcept body Expr Call AttributeLoad NameLoad attr Str Call NameLoad NameLoad Call AttributeLoad NameLoad attr handlers ExceptHandler body Pass Expr Call AttributeLoad NameLoad attr NameLoad orelse TryExcept body Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr body Pass If NameLoad body Assign NameStore Call NameLoad SubscriptLoad Call AttributeLoad NameLoad attr NameLoad ListLoad ListLoad Num Index Num Assign NameStore ListComp NameLoad comprehension NameStore NameLoad CompareNotIn NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Assign SubscriptStore AttributeLoad NameLoad attr Index NameLoad NameLoad AugAssignAdd AttributeStore NameLoad attr Call NameLoad NameLoad For NameStore NameLoad body Delete SubscriptDel AttributeLoad NameLoad attr Index NameLoad Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str TupleLoad AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr decorator_list decorator_list
N/A N/A 
Protocol-agnostic socket pooler.

This code is both extremely tested and hard to test.
Modify with caution :-)

"There are two ways of constructing a software design:
One way is to make it so simple that there are obviously no deficiencies,
and the other way is to make it so complicated that there are no obvious deficiencies."
-CAR Hoare, 1980 Turing Award lecture

In particular: it is tempting to attempt to auto-reconnect and re-try at this layer.
This is not possible to do correctly however, since only the protocol aware clients
know what a retry entails.  (e.g. SSL handshake, reset protocol state)
 N/A time N/A select N/A socket N/A gevent N/A ll N/A ml N/A N/A ll LLogger SocketPool N/A object N/A __init__ N/A N/A self timeout max_sockets N/A 0.25 800 N/A N/A async N/A N/A self timeout timeout N/A N/A self free_socks_by_addr N/A N/A N/A self sock_idle_times N/A N/A N/A self killsock N/A async killsock N/A N/A self total_sockets 0 N/A N/A self max_socks_by_addr N/A N/A N/A self default_max_socks_per_addr 50 N/A N/A self max_sockets 800 N/A acquire N/A N/A self addr N/A N/A N/A N/A N/A N/A N/A self cull N/A N/A N/A Exception N/A e N/A N/A N/A N/A ml ld Exception from cull: {0!r} e N/A socks N/A N/A N/A self free_socks_by_addr get addr N/A socks N/A N/A sock N/A N/A socks pop N/A N/A N/A self sock_idle_times N/A sock N/A N/A N/A N/A N/A ml ld Acquiring sock {0}/FD {1} N/A str N/A id sock N/A str N/A N/A sock fileno N/A N/A N/A N/A N/A sock N/A None N/A release N/A N/A self sock N/A N/A N/A N/A N/A N/A N/A ml ld Releasing sock {0} /FD {1} N/A str N/A id sock N/A str N/A N/A sock fileno N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A select select N/A sock N/A N/A 0 N/A 0 N/A N/A N/A N/A self killsock sock N/A N/A N/A N/A N/A N/A addr N/A N/A sock getpeername N/A addr_socks N/A N/A N/A self free_socks_by_addr setdefault addr N/A N/A N/A self total_sockets 1 N/A N/A N/A self sock_idle_times N/A sock N/A N/A time time N/A N/A N/A addr_socks append sock N/A N/A N/A self reduce_addr_size addr N/A N/A N/A self max_socks_by_addr get addr N/A self default_max_socks_per_addr N/A N/A N/A self reduce_size N/A self max_sockets N/A reduce_size N/A N/A self size N/A N/A N/A 
        reduce to the specified size by killing the oldest sockets
        returns a greenlet that can be joined on to wait for all sockets to close
         N/A N/A N/A self total_sockets size N/A N/A N/A num_culling N/A N/A self total_sockets size N/A culled N/A N/A sorted N/A N/A v k N/A N/A k v N/A N/A N/A self sock_idle_times iteritems N/A N/A num_culling N/A N/A self total_sockets num_culling N/A N/A N/A N/A self _remove_sock N/A e N/A 1 N/A e culled N/A reduce_addr_size N/A N/A self addr size N/A N/A N/A 
        reduce the number of sockets pooled on the specified address to size
        returns a greenlet that can be joined on to wait for all sockets to close
         N/A addr_socks N/A N/A N/A self free_socks_by_addr get addr N/A N/A N/A N/A len addr_socks size N/A N/A N/A num_culling N/A N/A len addr_socks size N/A culled N/A N/A sorted N/A N/A N/A N/A self sock_idle_times N/A e e N/A e addr_socks N/A N/A num_culling N/A N/A self total_sockets num_culling N/A N/A N/A N/A self _remove_sock N/A e N/A 1 N/A e culled N/A _remove_sock N/A N/A self sock N/A N/A N/A N/A N/A N/A N/A self free_socks_by_addr N/A N/A N/A sock getpeername remove sock N/A N/A N/A self sock_idle_times N/A sock N/A N/A N/A gevent spawn N/A self killsock sock N/A socks_pooled_for_addr N/A N/A self addr N/A N/A N/A N/A len N/A N/A N/A self free_socks_by_addr get addr N/A N/A cull N/A N/A self N/A N/A N/A culled N/A N/A N/A self total_sockets 0 N/A addr N/A self free_socks_by_addr N/A N/A live N/A N/A sock N/A N/A self free_socks_by_addr N/A addr N/A N/A N/A N/A N/A N/A time time N/A N/A N/A self sock_idle_times get sock 0 N/A self timeout N/A N/A N/A N/A N/A N/A ml ld Going to Close sock {{{0}}}/FD {1} N/A id sock N/A N/A sock fileno N/A N/A N/A N/A N/A N/A N/A culled append sock N/A N/A N/A N/A N/A N/A sock fileno N/A N/A N/A live append sock N/A N/A N/A N/A socket error N/A N/A N/A live N/A N/A readable N/A set N/A N/A N/A select select live N/A N/A 0 N/A 0 N/A live N/A s N/A s live N/A s readable N/A N/A N/A culled extend readable N/A N/A N/A self free_socks_by_addr N/A addr live N/A N/A self total_sockets N/A len live N/A sock culled N/A N/A N/A N/A self sock_idle_times N/A sock N/A N/A N/A gevent spawn N/A self killsock sock N/A __repr__ N/A N/A self N/A N/A N/A N/A <%s nsocks=%r/%r naddrs=%r> N/A N/A N/A self __class__ __name__ N/A self total_sockets N/A self max_sockets N/A len N/A self free_socks_by_addr N/A N/A