portage.util._eventloop.asyncio_event_loop module

class portage.util._eventloop.asyncio_event_loop.AsyncioEventLoop(loop=None)

Bases: asyncio.events.AbstractEventLoop

Implementation of asyncio.AbstractEventLoop which wraps asyncio’s event loop and is minimally compatible with _PortageEventLoop.

property _asyncio_child_watcher

Portage internals use this as a layer of indirection for asyncio.get_child_watcher(), in order to support versions of python where asyncio is not available.

Return type

asyncio.AbstractChildWatcher

Returns

the internal event loop’s AbstractChildWatcher interface

property _asyncio_wrapper

Portage internals use this as a layer of indirection in cases where a wrapper around an asyncio.AbstractEventLoop implementation is needed for purposes of compatiblity.

Return type

asyncio.AbstractEventLoop

Returns

the internal event loop’s AbstractEventLoop interface

_create_future()

Provide AbstractEventLoop.create_future() for python3.4.

static _internal_caller_exception_handler(loop, context)

An exception handler which drops to a pdb shell if std* streams refer to a tty, and otherwise kills the process with SIGTERM.

In order to avoid potential interference with API consumers, this implementation is only used when portage._internal_caller is True.

_run_until_complete(future)

An implementation of AbstractEventLoop.run_until_complete that supresses spurious error messages like the following reported in bug 655656:

Exception ignored when trying to write to the signal wakeup fd: BlockingIOError: [Errno 11] Resource temporarily unavailable

In order to avoid potential interference with API consumers, this implementation is only used when portage._internal_caller is True.

_timer_handle_cancelled(handle)

Notification that a TimerHandle has been cancelled.

add_reader(fd, callback, *args)
add_signal_handler(sig, callback, *args)
add_writer(fd, callback, *args)
call_at(when, callback, *args, context=None)
call_exception_handler(context)
call_later(delay, callback, *args, context=None)
call_soon(callback, *args, context=None)
call_soon_threadsafe(callback, *args, context=None)
close()

Close the loop.

The loop should not be running.

This is idempotent and irreversible.

No other methods should be called after this one.

async connect_accepted_socket(protocol_factory, sock, *, ssl=None, ssl_handshake_timeout=None)

Handle an accepted connection.

This is used by servers that accept connections outside of asyncio, but use asyncio to handle connections.

This method is a coroutine. When completed, the coroutine returns a (transport, protocol) pair.

async connect_read_pipe(protocol_factory, pipe)

Register read pipe in event loop. Set the pipe to non-blocking mode.

protocol_factory should instantiate object with Protocol interface. pipe is a file-like object. Return pair (transport, protocol), where transport supports the ReadTransport interface.

async connect_write_pipe(protocol_factory, pipe)

Register write pipe in event loop.

protocol_factory should instantiate object with BaseProtocol interface. Pipe is file-like object already switched to nonblocking. Return pair (transport, protocol), where transport support WriteTransport interface.

async create_connection(protocol_factory, host=None, port=None, *, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None, ssl_handshake_timeout=None, happy_eyeballs_delay=None, interleave=None)
async create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, *, family=0, proto=0, flags=0, reuse_address=None, reuse_port=None, allow_broadcast=None, sock=None)

A coroutine which creates a datagram endpoint.

This method will try to establish the endpoint in the background. When successful, the coroutine returns a (transport, protocol) pair.

protocol_factory must be a callable returning a protocol instance.

socket family AF_INET, socket.AF_INET6 or socket.AF_UNIX depending on host (or family if specified), socket type SOCK_DGRAM.

reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified it will automatically be set to True on UNIX.

reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows and some UNIX’s. If the SO_REUSEPORT constant is not defined then this capability is unsupported.

allow_broadcast tells the kernel to allow this endpoint to send messages to the broadcast address.

sock can optionally be specified in order to use a preexisting socket object.

create_future()
async create_server(protocol_factory, host=None, port=None, *, family=AddressFamily.AF_UNSPEC, flags=AddressInfo.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None, reuse_port=None, ssl_handshake_timeout=None, start_serving=True)

A coroutine which creates a TCP server bound to host and port.

The return value is a Server object which can be used to stop the service.

If host is an empty string or None all interfaces are assumed and a list of multiple sockets will be returned (most likely one for IPv4 and another one for IPv6). The host parameter can also be a sequence (e.g. list) of hosts to bind to.

family can be set to either AF_INET or AF_INET6 to force the socket to use IPv4 or IPv6. If not set it will be determined from host (defaults to AF_UNSPEC).

flags is a bitmask for getaddrinfo().

sock can optionally be specified in order to use a preexisting socket object.

backlog is the maximum number of queued connections passed to listen() (defaults to 100).

ssl can be set to an SSLContext to enable SSL over the accepted connections.

reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified will automatically be set to True on UNIX.

reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows.

ssl_handshake_timeout is the time in seconds that an SSL server will wait for completion of the SSL handshake before aborting the connection. Default is 60s.

start_serving set to True (default) causes the created server to start accepting connections immediately. When set to False, the user should await Server.start_serving() or Server.serve_forever() to make the server to start accepting connections.

create_task(coro, *, name=None)
async create_unix_connection(protocol_factory, path=None, *, ssl=None, sock=None, server_hostname=None, ssl_handshake_timeout=None)
async create_unix_server(protocol_factory, path=None, *, sock=None, backlog=100, ssl=None, ssl_handshake_timeout=None, start_serving=True)

A coroutine which creates a UNIX Domain Socket server.

The return value is a Server object, which can be used to stop the service.

path is a str, representing a file system path to bind the server socket to.

sock can optionally be specified in order to use a preexisting socket object.

backlog is the maximum number of queued connections passed to listen() (defaults to 100).

ssl can be set to an SSLContext to enable SSL over the accepted connections.

ssl_handshake_timeout is the time in seconds that an SSL server will wait for the SSL handshake to complete (defaults to 60s).

start_serving set to True (default) causes the created server to start accepting connections immediately. When set to False, the user should await Server.start_serving() or Server.serve_forever() to make the server to start accepting connections.

default_exception_handler(context)
get_debug()
get_exception_handler()
get_task_factory()
async getaddrinfo(host, port, *, family=0, type=0, proto=0, flags=0)
async getnameinfo(sockaddr, flags=0)
is_closed()

Returns True if the event loop was closed.

is_running()

Return whether the event loop is currently running.

remove_reader(fd)
remove_signal_handler(sig)
remove_writer(fd)
run_forever()

Run the event loop until stop() is called.

run_in_executor(executor, func, *args)
run_until_complete(future)

Run the event loop until a Future is done.

Return the Future’s result, or raise its exception.

async sendfile(transport, file, offset=0, count=None, *, fallback=True)

Send a file through a transport.

Return an amount of sent bytes.

set_debug(enabled)
set_default_executor(executor)
set_exception_handler(handler)
set_task_factory(factory)
async shutdown_asyncgens()

Shutdown all active asynchronous generators.

async shutdown_default_executor()

Schedule the shutdown of the default executor.

async sock_accept(sock)
async sock_connect(sock, address)
async sock_recv(sock, nbytes)
async sock_recv_into(sock, buf)
async sock_sendall(sock, data)
async sock_sendfile(sock, file, offset=0, count=None, *, fallback=None)
async start_tls(transport, protocol, sslcontext, *, server_side=False, server_hostname=None, ssl_handshake_timeout=None)

Upgrade a transport to TLS.

Return a new transport that protocol should start using immediately.

stop()

Stop the event loop as soon as reasonable.

Exactly how soon that is may depend on the implementation, but no more I/O callbacks should be scheduled.

async subprocess_exec(protocol_factory, *args, stdin=- 1, stdout=- 1, stderr=- 1, **kwargs)
async subprocess_shell(protocol_factory, cmd, *, stdin=- 1, stdout=- 1, stderr=- 1, **kwargs)
time()
class portage.util._eventloop.asyncio_event_loop._ChildWatcherThreadSafetyWrapper(loop, real_watcher)

Bases: asyncio.unix_events.AbstractChildWatcher

_child_exit(pid, status, callback, *args)
add_child_handler(pid, callback, *args)

Register a new child handler.

Arrange for callback(pid, returncode, *args) to be called when process ‘pid’ terminates. Specifying another callback for the same process replaces the previous handler.

Note: callback() must be thread-safe.

attach_loop(loop)

Attach the watcher to an event loop.

If the watcher was previously attached to an event loop, then it is first detached before attaching to the new loop.

Note: loop may be None.

close()

Close the watcher.

This must be called to make sure that any underlying resource is freed.

is_active()

Return True if the watcher is active and is used by the event loop.

Return True if the watcher is installed and ready to handle process exit notifications.

remove_child_handler(pid)

Removes the handler for process ‘pid’.

The function returns True if the handler was successfully removed, False if there was nothing to remove.