doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
coroutine loop.sock_recv_into(sock, buf) Receive data from sock into the buf buffer. Modeled after the blocking socket.recv_into() method. Return the number of bytes written to the buffer. sock must be a non-blocking socket. New in version 3.7.
python.library.asyncio-eventloop#asyncio.loop.sock_recv_into
coroutine loop.sock_sendall(sock, data) Send data to the sock socket. Asynchronous version of socket.sendall(). This method continues to send to the socket until either all data in data has been sent or an error occurs. None is returned on success. On error, an exception is raised. Additionally, there is no way to de...
python.library.asyncio-eventloop#asyncio.loop.sock_sendall
coroutine loop.sock_sendfile(sock, file, offset=0, count=None, *, fallback=True) Send a file using high-performance os.sendfile if possible. Return the total number of bytes sent. Asynchronous version of socket.sendfile(). sock must be a non-blocking socket.SOCK_STREAM socket. file must be a regular file object open ...
python.library.asyncio-eventloop#asyncio.loop.sock_sendfile
coroutine loop.start_tls(transport, protocol, sslcontext, *, server_side=False, server_hostname=None, ssl_handshake_timeout=None) Upgrade an existing transport-based connection to TLS. Return a new transport instance, that the protocol must start using immediately after the await. The transport instance passed to the...
python.library.asyncio-eventloop#asyncio.loop.start_tls
loop.stop() Stop the event loop.
python.library.asyncio-eventloop#asyncio.loop.stop
coroutine loop.subprocess_exec(protocol_factory, *args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) Create a subprocess from one or more string arguments specified by args. args must be a list of strings represented by: str; or bytes, encoded to the filesystem encoding. The fir...
python.library.asyncio-eventloop#asyncio.loop.subprocess_exec
coroutine loop.subprocess_shell(protocol_factory, cmd, *, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) Create a subprocess from cmd, which can be a str or a bytes string encoded to the filesystem encoding, using the platform’s “shell” syntax. This is similar to the standard library...
python.library.asyncio-eventloop#asyncio.loop.subprocess_shell
loop.time() Return the current time, as a float value, according to the event loop’s internal monotonic clock.
python.library.asyncio-eventloop#asyncio.loop.time
class asyncio.MultiLoopChildWatcher This implementation registers a SIGCHLD signal handler on instantiation. That can break third-party code that installs a custom handler for SIGCHLD signal. The watcher avoids disrupting other code spawning processes by polling every process explicitly on a SIGCHLD signal. There is ...
python.library.asyncio-policy#asyncio.MultiLoopChildWatcher
asyncio.new_event_loop() Create a new event loop object.
python.library.asyncio-eventloop#asyncio.new_event_loop
coroutine asyncio.open_connection(host=None, port=None, *, loop=None, limit=None, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None, ssl_handshake_timeout=None) Establish a network connection and return a pair of (reader, writer) objects. The returned reader and writer objects are...
python.library.asyncio-stream#asyncio.open_connection
coroutine asyncio.open_unix_connection(path=None, *, loop=None, limit=None, ssl=None, sock=None, server_hostname=None, ssl_handshake_timeout=None) Establish a Unix socket connection and return a pair of (reader, writer). Similar to open_connection() but operates on Unix sockets. See also the documentation of loop.cre...
python.library.asyncio-stream#asyncio.open_unix_connection
class asyncio.PidfdChildWatcher This implementation polls process file descriptors (pidfds) to await child process termination. In some respects, PidfdChildWatcher is a “Goldilocks” child watcher implementation. It doesn’t require signals or threads, doesn’t interfere with any processes launched outside the event loo...
python.library.asyncio-policy#asyncio.PidfdChildWatcher
class asyncio.PriorityQueue A variant of Queue; retrieves entries in priority order (lowest first). Entries are typically tuples of the form (priority_number, data).
python.library.asyncio-queue#asyncio.PriorityQueue
class asyncio.ProactorEventLoop An event loop for Windows that uses “I/O Completion Ports” (IOCP). Availability: Windows. See also MSDN documentation on I/O Completion Ports.
python.library.asyncio-eventloop#asyncio.ProactorEventLoop
class asyncio.Protocol(BaseProtocol) The base class for implementing streaming protocols (TCP, Unix sockets, etc).
python.library.asyncio-protocol#asyncio.Protocol
Protocol.data_received(data) Called when some data is received. data is a non-empty bytes object containing the incoming data. Whether the data is buffered, chunked or reassembled depends on the transport. In general, you shouldn’t rely on specific semantics and instead make your parsing generic and flexible. However...
python.library.asyncio-protocol#asyncio.Protocol.data_received
Protocol.eof_received() Called when the other end signals it won’t send any more data (for example by calling transport.write_eof(), if the other end also uses asyncio). This method may return a false value (including None), in which case the transport will close itself. Conversely, if this method returns a true valu...
python.library.asyncio-protocol#asyncio.Protocol.eof_received
class asyncio.Queue(maxsize=0, *, loop=None) A first in, first out (FIFO) queue. If maxsize is less than or equal to zero, the queue size is infinite. If it is an integer greater than 0, then await put() blocks when the queue reaches maxsize until an item is removed by get(). Unlike the standard library threading que...
python.library.asyncio-queue#asyncio.Queue
empty() Return True if the queue is empty, False otherwise.
python.library.asyncio-queue#asyncio.Queue.empty
full() Return True if there are maxsize items in the queue. If the queue was initialized with maxsize=0 (the default), then full() never returns True.
python.library.asyncio-queue#asyncio.Queue.full
coroutine get() Remove and return an item from the queue. If queue is empty, wait until an item is available.
python.library.asyncio-queue#asyncio.Queue.get
get_nowait() Return an item if one is immediately available, else raise QueueEmpty.
python.library.asyncio-queue#asyncio.Queue.get_nowait
coroutine join() Block until all items in the queue have been received and processed. The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer coroutine calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count...
python.library.asyncio-queue#asyncio.Queue.join
maxsize Number of items allowed in the queue.
python.library.asyncio-queue#asyncio.Queue.maxsize
coroutine put(item) Put an item into the queue. If the queue is full, wait until a free slot is available before adding the item.
python.library.asyncio-queue#asyncio.Queue.put
put_nowait(item) Put an item into the queue without blocking. If no free slot is immediately available, raise QueueFull.
python.library.asyncio-queue#asyncio.Queue.put_nowait
qsize() Return the number of items in the queue.
python.library.asyncio-queue#asyncio.Queue.qsize
task_done() Indicate that a formerly enqueued task is complete. Used by queue consumers. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete. If a join() is currently blocking, it will resume when all items have been processed (meaning that...
python.library.asyncio-queue#asyncio.Queue.task_done
exception asyncio.QueueEmpty This exception is raised when the get_nowait() method is called on an empty queue.
python.library.asyncio-queue#asyncio.QueueEmpty
exception asyncio.QueueFull Exception raised when the put_nowait() method is called on a queue that has reached its maxsize.
python.library.asyncio-queue#asyncio.QueueFull
class asyncio.ReadTransport(BaseTransport) A base transport for read-only connections. Instances of the ReadTransport class are returned from the loop.connect_read_pipe() event loop method and are also used by subprocess-related methods like loop.subprocess_exec().
python.library.asyncio-protocol#asyncio.ReadTransport
ReadTransport.is_reading() Return True if the transport is receiving new data. New in version 3.7.
python.library.asyncio-protocol#asyncio.ReadTransport.is_reading
ReadTransport.pause_reading() Pause the receiving end of the transport. No data will be passed to the protocol’s protocol.data_received() method until resume_reading() is called. Changed in version 3.7: The method is idempotent, i.e. it can be called when the transport is already paused or closed.
python.library.asyncio-protocol#asyncio.ReadTransport.pause_reading
ReadTransport.resume_reading() Resume the receiving end. The protocol’s protocol.data_received() method will be called once again if some data is available for reading. Changed in version 3.7: The method is idempotent, i.e. it can be called when the transport is already reading.
python.library.asyncio-protocol#asyncio.ReadTransport.resume_reading
asyncio.run(coro, *, debug=False) Execute the coroutine coro and return the result. This function runs the passed coroutine, taking care of managing the asyncio event loop, finalizing asynchronous generators, and closing the threadpool. This function cannot be called when another asyncio event loop is running in the ...
python.library.asyncio-task#asyncio.run
asyncio.run_coroutine_threadsafe(coro, loop) Submit a coroutine to the given event loop. Thread-safe. Return a concurrent.futures.Future to wait for the result from another OS thread. This function is meant to be called from a different OS thread than the one where the event loop is running. Example: # Create a corou...
python.library.asyncio-task#asyncio.run_coroutine_threadsafe
class asyncio.SafeChildWatcher This implementation uses active event loop from the main thread to handle SIGCHLD signal. If the main thread has no running event loop another thread cannot spawn a subprocess (RuntimeError is raised). The watcher avoids disrupting other code spawning processes by polling every process ...
python.library.asyncio-policy#asyncio.SafeChildWatcher
class asyncio.SelectorEventLoop An event loop based on the selectors module. Uses the most efficient selector available for the given platform. It is also possible to manually configure the exact selector implementation to be used: import asyncio import selectors selector = selectors.SelectSelector() loop = asyncio....
python.library.asyncio-eventloop#asyncio.SelectorEventLoop
class asyncio.Semaphore(value=1, *, loop=None) A Semaphore object. Not thread-safe. A semaphore manages an internal counter which is decremented by each acquire() call and incremented by each release() call. The counter can never go below zero; when acquire() finds that it is zero, it blocks, waiting until some task ...
python.library.asyncio-sync#asyncio.Semaphore
coroutine acquire() Acquire a semaphore. If the internal counter is greater than zero, decrement it by one and return True immediately. If it is zero, wait until a release() is called and return True.
python.library.asyncio-sync#asyncio.Semaphore.acquire
locked() Returns True if semaphore can not be acquired immediately.
python.library.asyncio-sync#asyncio.Semaphore.locked
release() Release a semaphore, incrementing the internal counter by one. Can wake up a task waiting to acquire the semaphore. Unlike BoundedSemaphore, Semaphore allows making more release() calls than acquire() calls.
python.library.asyncio-sync#asyncio.Semaphore.release
exception asyncio.SendfileNotAvailableError The “sendfile” syscall is not available for the given socket or file type. A subclass of RuntimeError.
python.library.asyncio-exceptions#asyncio.SendfileNotAvailableError
class asyncio.Server Server objects are asynchronous context managers. When used in an async with statement, it’s guaranteed that the Server object is closed and not accepting new connections when the async with statement is completed: srv = await loop.create_server(...) async with srv: # some code # At this po...
python.library.asyncio-eventloop#asyncio.Server
close() Stop serving: close listening sockets and set the sockets attribute to None. The sockets that represent existing incoming client connections are left open. The server is closed asynchronously, use the wait_closed() coroutine to wait until the server is closed.
python.library.asyncio-eventloop#asyncio.Server.close
get_loop() Return the event loop associated with the server object. New in version 3.7.
python.library.asyncio-eventloop#asyncio.Server.get_loop
is_serving() Return True if the server is accepting new connections. New in version 3.7.
python.library.asyncio-eventloop#asyncio.Server.is_serving
coroutine serve_forever() Start accepting connections until the coroutine is cancelled. Cancellation of serve_forever task causes the server to be closed. This method can be called if the server is already accepting connections. Only one serve_forever task can exist per one Server object. Example: async def client_co...
python.library.asyncio-eventloop#asyncio.Server.serve_forever
sockets List of socket.socket objects the server is listening on. Changed in version 3.7: Prior to Python 3.7 Server.sockets used to return an internal list of server sockets directly. In 3.7 a copy of that list is returned.
python.library.asyncio-eventloop#asyncio.Server.sockets
coroutine start_serving() Start accepting connections. This method is idempotent, so it can be called when the server is already being serving. The start_serving keyword-only parameter to loop.create_server() and asyncio.start_server() allows creating a Server object that is not accepting connections initially. In th...
python.library.asyncio-eventloop#asyncio.Server.start_serving
coroutine wait_closed() Wait until the close() method completes.
python.library.asyncio-eventloop#asyncio.Server.wait_closed
asyncio.set_child_watcher(watcher) Set the current child watcher to watcher for the current policy. watcher must implement methods defined in the AbstractChildWatcher base class.
python.library.asyncio-policy#asyncio.set_child_watcher
asyncio.set_event_loop(loop) Set loop as a current event loop for the current OS thread.
python.library.asyncio-eventloop#asyncio.set_event_loop
asyncio.set_event_loop_policy(policy) Set the current process-wide policy to policy. If policy is set to None, the default policy is restored.
python.library.asyncio-policy#asyncio.set_event_loop_policy
awaitable asyncio.shield(aw, *, loop=None) Protect an awaitable object from being cancelled. If aw is a coroutine it is automatically scheduled as a Task. The statement: res = await shield(something()) is equivalent to: res = await something() except that if the coroutine containing it is cancelled, the Task runnin...
python.library.asyncio-task#asyncio.shield
coroutine asyncio.sleep(delay, result=None, *, loop=None) Block for delay seconds. If result is provided, it is returned to the caller when the coroutine completes. sleep() always suspends the current task, allowing other tasks to run. Deprecated since version 3.8, will be removed in version 3.10: The loop parameter...
python.library.asyncio-task#asyncio.sleep
coroutine asyncio.start_server(client_connected_cb, host=None, port=None, *, loop=None, limit=None, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None, reuse_port=None, ssl_handshake_timeout=None, start_serving=True) Start a socket server. The client_connected_cb ca...
python.library.asyncio-stream#asyncio.start_server
coroutine asyncio.start_unix_server(client_connected_cb, path=None, *, loop=None, limit=None, sock=None, backlog=100, ssl=None, ssl_handshake_timeout=None, start_serving=True) Start a Unix socket server. Similar to start_server() but works with Unix sockets. See also the documentation of loop.create_unix_server(). Av...
python.library.asyncio-stream#asyncio.start_unix_server
class asyncio.StreamReader Represents a reader object that provides APIs to read data from the IO stream. It is not recommended to instantiate StreamReader objects directly; use open_connection() and start_server() instead. coroutine read(n=-1) Read up to n bytes. If n is not provided, or set to -1, read until EO...
python.library.asyncio-stream#asyncio.StreamReader
at_eof() Return True if the buffer is empty and feed_eof() was called.
python.library.asyncio-stream#asyncio.StreamReader.at_eof
coroutine read(n=-1) Read up to n bytes. If n is not provided, or set to -1, read until EOF and return all read bytes. If EOF was received and the internal buffer is empty, return an empty bytes object.
python.library.asyncio-stream#asyncio.StreamReader.read
coroutine readexactly(n) Read exactly n bytes. Raise an IncompleteReadError if EOF is reached before n can be read. Use the IncompleteReadError.partial attribute to get the partially read data.
python.library.asyncio-stream#asyncio.StreamReader.readexactly
coroutine readline() Read one line, where “line” is a sequence of bytes ending with \n. If EOF is received and \n was not found, the method returns partially read data. If EOF is received and the internal buffer is empty, return an empty bytes object.
python.library.asyncio-stream#asyncio.StreamReader.readline
coroutine readuntil(separator=b'\n') Read data from the stream until separator is found. On success, the data and separator will be removed from the internal buffer (consumed). Returned data will include the separator at the end. If the amount of data read exceeds the configured stream limit, a LimitOverrunError exce...
python.library.asyncio-stream#asyncio.StreamReader.readuntil
class asyncio.StreamWriter Represents a writer object that provides APIs to write data to the IO stream. It is not recommended to instantiate StreamWriter objects directly; use open_connection() and start_server() instead. write(data) The method attempts to write the data to the underlying socket immediately. If ...
python.library.asyncio-stream#asyncio.StreamWriter
can_write_eof() Return True if the underlying transport supports the write_eof() method, False otherwise.
python.library.asyncio-stream#asyncio.StreamWriter.can_write_eof
close() The method closes the stream and the underlying socket. The method should be used along with the wait_closed() method: stream.close() await stream.wait_closed()
python.library.asyncio-stream#asyncio.StreamWriter.close
coroutine drain() Wait until it is appropriate to resume writing to the stream. Example: writer.write(data) await writer.drain() This is a flow control method that interacts with the underlying IO write buffer. When the size of the buffer reaches the high watermark, drain() blocks until the size of the buffer is dra...
python.library.asyncio-stream#asyncio.StreamWriter.drain
get_extra_info(name, default=None) Access optional transport information; see BaseTransport.get_extra_info() for details.
python.library.asyncio-stream#asyncio.StreamWriter.get_extra_info
is_closing() Return True if the stream is closed or in the process of being closed. New in version 3.7.
python.library.asyncio-stream#asyncio.StreamWriter.is_closing
transport Return the underlying asyncio transport.
python.library.asyncio-stream#asyncio.StreamWriter.transport
coroutine wait_closed() Wait until the stream is closed. Should be called after close() to wait until the underlying connection is closed. New in version 3.7.
python.library.asyncio-stream#asyncio.StreamWriter.wait_closed
write(data) The method attempts to write the data to the underlying socket immediately. If that fails, the data is queued in an internal write buffer until it can be sent. The method should be used along with the drain() method: stream.write(data) await stream.drain()
python.library.asyncio-stream#asyncio.StreamWriter.write
writelines(data) The method writes a list (or any iterable) of bytes to the underlying socket immediately. If that fails, the data is queued in an internal write buffer until it can be sent. The method should be used along with the drain() method: stream.writelines(lines) await stream.drain()
python.library.asyncio-stream#asyncio.StreamWriter.writelines
write_eof() Close the write end of the stream after the buffered write data is flushed.
python.library.asyncio-stream#asyncio.StreamWriter.write_eof
class asyncio.SubprocessProtocol(BaseProtocol) The base class for implementing protocols communicating with child processes (unidirectional pipes).
python.library.asyncio-protocol#asyncio.SubprocessProtocol
SubprocessProtocol.pipe_connection_lost(fd, exc) Called when one of the pipes communicating with the child process is closed. fd is the integer file descriptor that was closed.
python.library.asyncio-protocol#asyncio.SubprocessProtocol.pipe_connection_lost
SubprocessProtocol.pipe_data_received(fd, data) Called when the child process writes data into its stdout or stderr pipe. fd is the integer file descriptor of the pipe. data is a non-empty bytes object containing the received data.
python.library.asyncio-protocol#asyncio.SubprocessProtocol.pipe_data_received
SubprocessProtocol.process_exited() Called when the child process has exited.
python.library.asyncio-protocol#asyncio.SubprocessProtocol.process_exited
class asyncio.SubprocessTransport(BaseTransport) An abstraction to represent a connection between a parent and its child OS process. Instances of the SubprocessTransport class are returned from event loop methods loop.subprocess_shell() and loop.subprocess_exec().
python.library.asyncio-protocol#asyncio.SubprocessTransport
SubprocessTransport.close() Kill the subprocess by calling the kill() method. If the subprocess hasn’t returned yet, and close transports of stdin, stdout, and stderr pipes.
python.library.asyncio-protocol#asyncio.SubprocessTransport.close
SubprocessTransport.get_pid() Return the subprocess process id as an integer.
python.library.asyncio-protocol#asyncio.SubprocessTransport.get_pid
SubprocessTransport.get_pipe_transport(fd) Return the transport for the communication pipe corresponding to the integer file descriptor fd: 0: readable streaming transport of the standard input (stdin), or None if the subprocess was not created with stdin=PIPE 1: writable streaming transport of the standard outpu...
python.library.asyncio-protocol#asyncio.SubprocessTransport.get_pipe_transport
SubprocessTransport.get_returncode() Return the subprocess return code as an integer or None if it hasn’t returned, which is similar to the subprocess.Popen.returncode attribute.
python.library.asyncio-protocol#asyncio.SubprocessTransport.get_returncode
SubprocessTransport.kill() Kill the subprocess. On POSIX systems, the function sends SIGKILL to the subprocess. On Windows, this method is an alias for terminate(). See also subprocess.Popen.kill().
python.library.asyncio-protocol#asyncio.SubprocessTransport.kill
SubprocessTransport.send_signal(signal) Send the signal number to the subprocess, as in subprocess.Popen.send_signal().
python.library.asyncio-protocol#asyncio.SubprocessTransport.send_signal
SubprocessTransport.terminate() Stop the subprocess. On POSIX systems, this method sends SIGTERM to the subprocess. On Windows, the Windows API function TerminateProcess() is called to stop the subprocess. See also subprocess.Popen.terminate().
python.library.asyncio-protocol#asyncio.SubprocessTransport.terminate
class asyncio.Task(coro, *, loop=None, name=None) A Future-like object that runs a Python coroutine. Not thread-safe. Tasks are used to run coroutines in event loops. If a coroutine awaits on a Future, the Task suspends the execution of the coroutine and waits for the completion of the Future. When the Future is done...
python.library.asyncio-task#asyncio.Task
add_done_callback(callback, *, context=None) Add a callback to be run when the Task is done. This method should only be used in low-level callback-based code. See the documentation of Future.add_done_callback() for more details.
python.library.asyncio-task#asyncio.Task.add_done_callback
cancel(msg=None) Request the Task to be cancelled. This arranges for a CancelledError exception to be thrown into the wrapped coroutine on the next cycle of the event loop. The coroutine then has a chance to clean up or even deny the request by suppressing the exception with a try … … except CancelledError … finally ...
python.library.asyncio-task#asyncio.Task.cancel
cancelled() Return True if the Task is cancelled. The Task is cancelled when the cancellation was requested with cancel() and the wrapped coroutine propagated the CancelledError exception thrown into it.
python.library.asyncio-task#asyncio.Task.cancelled
done() Return True if the Task is done. A Task is done when the wrapped coroutine either returned a value, raised an exception, or the Task was cancelled.
python.library.asyncio-task#asyncio.Task.done
exception() Return the exception of the Task. If the wrapped coroutine raised an exception that exception is returned. If the wrapped coroutine returned normally this method returns None. If the Task has been cancelled, this method raises a CancelledError exception. If the Task isn’t done yet, this method raises an I...
python.library.asyncio-task#asyncio.Task.exception
get_coro() Return the coroutine object wrapped by the Task. New in version 3.8.
python.library.asyncio-task#asyncio.Task.get_coro
get_name() Return the name of the Task. If no name has been explicitly assigned to the Task, the default asyncio Task implementation generates a default name during instantiation. New in version 3.8.
python.library.asyncio-task#asyncio.Task.get_name
get_stack(*, limit=None) Return the list of stack frames for this Task. If the wrapped coroutine is not done, this returns the stack where it is suspended. If the coroutine has completed successfully or was cancelled, this returns an empty list. If the coroutine was terminated by an exception, this returns the list o...
python.library.asyncio-task#asyncio.Task.get_stack
print_stack(*, limit=None, file=None) Print the stack or traceback for this Task. This produces output similar to that of the traceback module for the frames retrieved by get_stack(). The limit argument is passed to get_stack() directly. The file argument is an I/O stream to which the output is written; by default ou...
python.library.asyncio-task#asyncio.Task.print_stack
remove_done_callback(callback) Remove callback from the callbacks list. This method should only be used in low-level callback-based code. See the documentation of Future.remove_done_callback() for more details.
python.library.asyncio-task#asyncio.Task.remove_done_callback
result() Return the result of the Task. If the Task is done, the result of the wrapped coroutine is returned (or if the coroutine raised an exception, that exception is re-raised.) If the Task has been cancelled, this method raises a CancelledError exception. If the Task’s result isn’t yet available, this method rais...
python.library.asyncio-task#asyncio.Task.result