network.pool Module

class wpull.network.pool.ConnectionPool(max_host_count: int=6, resolver: typing.Union=None, connection_factory: typing.Union=None, ssl_connection_factory: typing.Union=None, max_count: int=100)[source]

Bases: object

Connection pool.

Parameters:
  • max_host_count – Number of connections per host.
  • resolver – DNS resolver.
  • connection_factory – A function that accepts address and hostname arguments and returns a Connection instance.
  • ssl_connection_factory – A function that returns a SSLConnection instance. See connection_factory.
  • max_count – Limit on number of connections
acquire(host: str, port: int, use_ssl: bool=False, host_key: typing.Any=None) → wpull.network.connection.Connection[source]

Return an available connection.

Parameters:
  • host – A hostname or IP address.
  • port – Port number.
  • use_ssl – Whether to return a SSL connection.
  • host_key – If provided, it overrides the key used for per-host connection pooling. This is useful for proxies for example.

Coroutine.

clean(force: bool=False)[source]

Clean all closed connections.

Parameters:force – Clean connected and idle connections too.

Coroutine.

close()[source]

Close all the connections and clean up.

This instance will not be usable after calling this method.

count() → int[source]

Return number of connections.

host_pools
no_wait_release(connection: wpull.network.connection.Connection)[source]

Synchronous version of release().

release(connection: wpull.network.connection.Connection)[source]

Put a connection back in the pool.

Coroutine.

session(host: str, port: int, use_ssl: bool=False)[source]

Return a context manager that returns a connection.

Usage:

session = yield from connection_pool.session('example.com', 80)
with session as connection:
    connection.write(b'blah')
    connection.close()

Coroutine.

class wpull.network.pool.HappyEyeballsConnection(address, connection_factory, resolver, happy_eyeballs_table, is_ssl=False)[source]

Bases: object

Wrapper for happy eyeballs connection.

close()[source]
closed()[source]
connect()[source]
reset()[source]
class wpull.network.pool.HappyEyeballsTable(max_items=100, time_to_live=600)[source]

Bases: object

get_preferred(addr_1, addr_2)[source]

Return the preferred address.

set_preferred(preferred_addr, addr_1, addr_2)[source]

Set the preferred address.

class wpull.network.pool.HostPool(connection_factory: typing.Callable, max_connections: int=6)[source]

Bases: object

Connection pool for a host.

ready

Queue

Connections not in use.

busy

set

Connections in use.

acquire() → wpull.network.connection.Connection[source]

Register and return a connection.

Coroutine.

clean(force: bool=False)[source]

Clean closed connections.

Parameters:force – Clean connected and idle connections too.

Coroutine.

close()[source]

Forcibly close all connections.

This instance will not be usable after calling this method.

count() → int[source]

Return total number of connections.

empty() → bool[source]

Return whether the pool is empty.

release(connection: wpull.network.connection.Connection, reuse: bool=True)[source]

Unregister a connection.

Parameters:
  • connection – Connection instance returned from acquire().
  • reuse – If True, the connection is made available for reuse.

Coroutine.