neulab/docprompting-conala huggingface dataset:
awaitable asyncio.gather(*aws, loop=None, return_exceptions=False)  
Run awaitable objects in the aws sequence concurrently. If any awaitable in aws is a coroutine, it is automatically scheduled as a Task. If all awaitables are completed successfully, the result is an aggregate list of returned values. The order of result values corresponds to the order of awaitables in aws. If return_exceptions is False (default), the first raised exception is immediately propagated to the task that awaits on gather(). Other awaitables in the aws sequence won’t be cancelled and will continue to run. If return_exceptions is True, exceptions are treated the same as successful results, and aggregated in the result list. If gather() is cancelled, all submitted awaitables (that have not completed yet) are also cancelled. If any Task or Future from the aws sequence is cancelled, it is treated as if it raised CancelledError – the gather() call is not cancelled in this case. This is to prevent the cancellation of one submitted Task/Future to cause other Tasks/Futures to be cancelled.  Deprecated since version 3.8, will be removed in version 3.10: The loop parameter.  Example: import asyncio

async def factorial(name, number):
    f = 1
    for i in range(2, number + 1):
        print(f"Task {name}: Compute factorial({i})...")
        await asyncio.sleep(1)
        f *= i
    print(f"Task {name}: factorial({number}) = {f}")

async def main():
    # Schedule three calls *concurrently*:
    await asyncio.gather(
        factorial("A", 2),
        factorial("B", 3),
        factorial("C", 4),
    )

asyncio.run(main())

# Expected output:
#
#     Task A: Compute factorial(2)...
#     Task B: Compute factorial(2)...
#     Task C: Compute factorial(2)...
#     Task A: factorial(2) = 2
#     Task B: Compute factorial(3)...
#     Task C: Compute factorial(3)...
#     Task B: factorial(3) = 6
#     Task C: Compute factorial(4)...
#     Task C: factorial(4) = 24
  Note If return_exceptions is False, cancelling gather() after it has been marked done won’t cancel any submitted awaitables. For instance, gather can be marked done after propagating an exception to the caller, therefore, calling gather.cancel() after catching an exception (raised by one of the awaitables) from gather won’t cancel any other awaitables.   Changed in version 3.7: If the gather itself is cancelled, the cancellation is propagated regardless of return_exceptions.
asyncio.get_child_watcher()  
Return the current child watcher for the current policy.
asyncio.get_event_loop()  
Get the current event loop. If there is no current event loop set in the current OS thread, the OS thread is main, and set_event_loop() has not yet been called, asyncio will create a new event loop and set it as the current one. Because this function has rather complex behavior (especially when custom event loop policies are in use), using the get_running_loop() function is preferred to get_event_loop() in coroutines and callbacks. Consider also using the asyncio.run() function instead of using lower level functions to manually create and close an event loop.
asyncio.get_event_loop_policy()  
Return the current process-wide policy.
asyncio.get_running_loop()  
Return the running event loop in the current OS thread. If there is no running event loop a RuntimeError is raised. This function can only be called from a coroutine or a callback.  New in version 3.7.
class asyncio.Handle  
A callback wrapper object returned by loop.call_soon(), loop.call_soon_threadsafe().  
cancel()  
Cancel the callback. If the callback has already been canceled or executed, this method has no effect. 
  
cancelled()  
Return True if the callback was cancelled.  New in version 3.7.
cancel()  
Cancel the callback. If the callback has already been canceled or executed, this method has no effect.
cancelled()  
Return True if the callback was cancelled.  New in version 3.7.
exception asyncio.IncompleteReadError  
The requested read operation did not complete fully. Raised by the asyncio stream APIs. This exception is a subclass of EOFError.  
expected  
The total number (int) of expected bytes. 
  
partial  
A string of bytes read before the end of stream was reached.
exception asyncio.InvalidStateError  
Invalid internal state of Task or Future. Can be raised in situations like setting a result value for a Future object that already has a result value set.
asyncio.iscoroutine(obj)  
Return True if obj is a coroutine object. This method is different from inspect.iscoroutine() because it returns True for generator-based coroutines.
asyncio.iscoroutinefunction(func)  
Return True if func is a coroutine function. This method is different from inspect.iscoroutinefunction() because it returns True for generator-based coroutine functions decorated with @coroutine.
asyncio.isfuture(obj)  
Return True if obj is either of:  an instance of asyncio.Future, an instance of asyncio.Task, a Future-like object with a _asyncio_future_blocking attribute.   New in version 3.5.
class asyncio.LifoQueue  
A variant of Queue that retrieves most recently added entries first (last in, first out).
exception asyncio.LimitOverrunError  
Reached the buffer size limit while looking for a separator. Raised by the asyncio stream APIs.  
consumed  
The total number of to be consumed bytes.
class asyncio.Lock(*, loop=None)  
Implements a mutex lock for asyncio tasks. Not thread-safe. An asyncio lock can be used to guarantee exclusive access to a shared resource. The preferred way to use a Lock is an async with statement: lock = asyncio.Lock()

# ... later
async with lock:
    # access shared state
 which is equivalent to: lock = asyncio.Lock()

# ... later
await lock.acquire()
try:
    # access shared state
finally:
    lock.release()
  Deprecated since version 3.8, will be removed in version 3.10: The loop parameter.   
coroutine acquire()  
Acquire the lock. This method waits until the lock is unlocked, sets it to locked and returns True. When more than one coroutine is blocked in acquire() waiting for the lock to be unlocked, only one coroutine eventually proceeds. Acquiring a lock is fair: the coroutine that proceeds will be the first coroutine that started waiting on the lock. 
  
release()  
Release the lock. When the lock is locked, reset it to unlocked and return. If the lock is unlocked, a RuntimeError is raised. 
  
locked()  
Return True if the lock is locked.
coroutine acquire()  
Acquire the lock. This method waits until the lock is unlocked, sets it to locked and returns True. When more than one coroutine is blocked in acquire() waiting for the lock to be unlocked, only one coroutine eventually proceeds. Acquiring a lock is fair: the coroutine that proceeds will be the first coroutine that started waiting on the lock.
release()  
Release the lock. When the lock is locked, reset it to unlocked and return. If the lock is unlocked, a RuntimeError is raised.
loop.add_reader(fd, callback, *args)  
Start monitoring the fd file descriptor for read availability and invoke callback with the specified arguments once fd is available for reading.
loop.add_signal_handler(signum, callback, *args)  
Set callback as the handler for the signum signal. The callback will be invoked by loop, along with other queued callbacks and runnable coroutines of that event loop. Unlike signal handlers registered using signal.signal(), a callback registered with this function is allowed to interact with the event loop. Raise ValueError if the signal number is invalid or uncatchable. Raise RuntimeError if there is a problem setting up the handler. Use functools.partial() to pass keyword arguments to callback. Like signal.signal(), this function must be invoked in the main thread.
loop.add_writer(fd, callback, *args)  
Start monitoring the fd file descriptor for write availability and invoke callback with the specified arguments once fd is available for writing. Use functools.partial() to pass keyword arguments to callback.
loop.call_at(when, callback, *args, context=None)  
Schedule callback to be called at the given absolute timestamp when (an int or a float), using the same time reference as loop.time(). This method’s behavior is the same as call_later(). An instance of asyncio.TimerHandle is returned which can be used to cancel the callback.  Changed in version 3.7: The context keyword-only parameter was added. See PEP 567 for more details.   Changed in version 3.8: In Python 3.7 and earlier with the default event loop implementation, the difference between when and the current time could not exceed one day. This has been fixed in Python 3.8.
loop.call_exception_handler(context)  
Call the current event loop exception handler. context is a dict object containing the following keys (new keys may be introduced in future Python versions):  ‘message’: Error message; ‘exception’ (optional): Exception object; ‘future’ (optional): asyncio.Future instance; ‘handle’ (optional): asyncio.Handle instance; ‘protocol’ (optional): Protocol instance; ‘transport’ (optional): Transport instance; ‘socket’ (optional): socket.socket instance.   Note This method should not be overloaded in subclassed event loops. For custom exception handling, use the set_exception_handler() method.
loop.call_later(delay, callback, *args, context=None)  
Schedule callback to be called after the given delay number of seconds (can be either an int or a float). An instance of asyncio.TimerHandle is returned which can be used to cancel the callback. callback will be called exactly once. If two callbacks are scheduled for exactly the same time, the order in which they are called is undefined. The optional positional args will be passed to the callback when it is called. If you want the callback to be called with keyword arguments use functools.partial(). An optional keyword-only context argument allows specifying a custom contextvars.Context for the callback to run in. The current context is used when no context is provided.  Changed in version 3.7: The context keyword-only parameter was added. See PEP 567 for more details.   Changed in version 3.8: In Python 3.7 and earlier with the default event loop implementation, the delay could not exceed one day. This has been fixed in Python 3.8.
loop.call_soon(callback, *args, context=None)  
Schedule the callback callback to be called with args arguments at the next iteration of the event loop. Callbacks are called in the order in which they are registered. Each callback will be called exactly once. An optional keyword-only context argument allows specifying a custom contextvars.Context for the callback to run in. The current context is used when no context is provided. An instance of asyncio.Handle is returned, which can be used later to cancel the callback. This method is not thread-safe.
loop.call_soon_threadsafe(callback, *args, context=None)  
A thread-safe variant of call_soon(). Must be used to schedule callbacks from another thread. See the concurrency and multithreading section of the documentation.
loop.close()  
Close the event loop. The loop must not be running when this function is called. Any pending callbacks will be discarded. This method clears all queues and shuts down the executor, but does not wait for the executor to finish. This method is idempotent and irreversible. No other methods should be called after the event loop is closed.
coroutine loop.connect_accepted_socket(protocol_factory, sock, *, ssl=None, ssl_handshake_timeout=None)  
Wrap an already accepted connection into a transport/protocol pair. This method can be used by servers that accept connections outside of asyncio but that use asyncio to handle them. Parameters:  
protocol_factory must be a callable returning a protocol implementation. 
sock is a preexisting socket object returned from socket.accept. 
ssl can be set to an SSLContext to enable SSL over the accepted connections. 
ssl_handshake_timeout is (for an SSL connection) the time in seconds to wait for the SSL handshake to complete before aborting the connection. 60.0 seconds if None (default).  Returns a (transport, protocol) pair.  New in version 3.7: The ssl_handshake_timeout parameter.   New in version 3.5.3.
coroutine loop.connect_read_pipe(protocol_factory, pipe)  
Register the read end of pipe in the event loop. protocol_factory must be a callable returning an asyncio protocol implementation. pipe is a file-like object. Return pair (transport, protocol), where transport supports the ReadTransport interface and protocol is an object instantiated by the protocol_factory. With SelectorEventLoop event loop, the pipe is set to non-blocking mode.
coroutine loop.connect_write_pipe(protocol_factory, pipe)  
Register the write end of pipe in the event loop. protocol_factory must be a callable returning an asyncio protocol implementation. pipe is file-like object. Return pair (transport, protocol), where transport supports WriteTransport interface and protocol is an object instantiated by the protocol_factory. With SelectorEventLoop event loop, the pipe is set to non-blocking mode.
coroutine loop.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)  
 Note The parameter reuse_address is no longer supported, as using SO_REUSEADDR poses a significant security concern for UDP. Explicitly passing reuse_address=True will raise an exception. When multiple processes with differing UIDs assign sockets to an identical UDP socket address with SO_REUSEADDR, incoming packets can become randomly distributed among the sockets. For supported platforms, reuse_port can be used as a replacement for similar functionality. With reuse_port, SO_REUSEPORT is used instead, which specifically prevents processes with differing UIDs from assigning sockets to the same socket address.  Create a datagram connection. The socket family can be either AF_INET, AF_INET6, or AF_UNIX, depending on host (or the family argument, if provided). The socket type will be SOCK_DGRAM. protocol_factory must be a callable returning a protocol implementation. A tuple of (transport, protocol) is returned on success. Other arguments:  
local_addr, if given, is a (local_host, local_port) tuple used to bind the socket to locally. The local_host and local_port are looked up using getaddrinfo(). 
remote_addr, if given, is a (remote_host, remote_port) tuple used to connect the socket to a remote address. The remote_host and remote_port are looked up using getaddrinfo(). 
family, proto, flags are the optional address family, protocol and flags to be passed through to getaddrinfo() for host resolution. If given, these should all be integers from the corresponding socket module constants. 
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 Unixes. 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, already connected, socket.socket object to be used by the transport. If specified, local_addr and remote_addr should be omitted (must be None).  See UDP echo client protocol and UDP echo server protocol examples.  Changed in version 3.4.4: The family, proto, flags, reuse_address, reuse_port, *allow_broadcast, and sock parameters were added.   Changed in version 3.8.1: The reuse_address parameter is no longer supported due to security concerns.   Changed in version 3.8: Added support for Windows.
loop.create_future()  
Create an asyncio.Future object attached to the event loop. This is the preferred way to create Futures in asyncio. This lets third-party event loops provide alternative implementations of the Future object (with better performance or instrumentation).  New in version 3.5.2.
coroutine loop.create_server(protocol_factory, host=None, port=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)  
Create a TCP server (socket type SOCK_STREAM) listening on port of the host address. Returns a Server object. Arguments:  
protocol_factory must be a callable returning a protocol implementation. 
The host parameter can be set to several types which determine where the server would be listening:  If host is a string, the TCP server is bound to a single network interface specified by host. If host is a sequence of strings, the TCP server is bound to all network interfaces specified by the sequence. 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).   
family can be set to either socket.AF_INET or AF_INET6 to force the socket to use IPv4 or IPv6. If not set, the family will be determined from host name (defaults to AF_UNSPEC). 
flags is a bitmask for getaddrinfo(). 
sock can optionally be specified in order to use a preexisting socket object. If specified, host and port must not be specified. 
backlog is the maximum number of queued connections passed to listen() (defaults to 100). 
ssl can be set to an SSLContext instance to enable TLS 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 (for a TLS server) the time in seconds to wait for the TLS handshake to complete before aborting the connection. 60.0 seconds if None (default). 
start_serving set to True (the default) causes the created server to start accepting connections immediately. When set to False, the user should await on Server.start_serving() or Server.serve_forever() to make the server to start accepting connections.   New in version 3.7: Added ssl_handshake_timeout and start_serving parameters.   Changed in version 3.6: The socket option TCP_NODELAY is set by default for all TCP connections.   Changed in version 3.5: Added support for SSL/TLS in ProactorEventLoop.   Changed in version 3.5.1: The host parameter can be a sequence of strings.   See also The start_server() function is a higher-level alternative API that returns a pair of StreamReader and StreamWriter that can be used in an async/await code.
loop.create_task(coro, *, name=None)  
Schedule the execution of a Coroutines. Return a Task object. Third-party event loops can use their own subclass of Task for interoperability. In this case, the result type is a subclass of Task. If the name argument is provided and not None, it is set as the name of the task using Task.set_name().  Changed in version 3.8: Added the name parameter.
coroutine loop.create_unix_connection(protocol_factory, path=None, *, ssl=None, sock=None, server_hostname=None, ssl_handshake_timeout=None)  
Create a Unix connection. The socket family will be AF_UNIX; socket type will be SOCK_STREAM. A tuple of (transport, protocol) is returned on success. path is the name of a Unix domain socket and is required, unless a sock parameter is specified. Abstract Unix sockets, str, bytes, and Path paths are supported. See the documentation of the loop.create_connection() method for information about arguments to this method. Availability: Unix.  New in version 3.7: The ssl_handshake_timeout parameter.   Changed in version 3.7: The path parameter can now be a path-like object.
coroutine loop.create_unix_server(protocol_factory, path=None, *, sock=None, backlog=100, ssl=None, ssl_handshake_timeout=None, start_serving=True)  
Similar to loop.create_server() but works with the AF_UNIX socket family. path is the name of a Unix domain socket, and is required, unless a sock argument is provided. Abstract Unix sockets, str, bytes, and Path paths are supported. See the documentation of the loop.create_server() method for information about arguments to this method. Availability: Unix.  New in version 3.7: The ssl_handshake_timeout and start_serving parameters.   Changed in version 3.7: The path parameter can now be a Path object.
loop.default_exception_handler(context)  
Default exception handler. This is called when an exception occurs and no exception handler is set. This can be called by a custom exception handler that wants to defer to the default handler behavior. context parameter has the same meaning as in call_exception_handler().
coroutine loop.getaddrinfo(host, port, *, family=0, type=0, proto=0, flags=0)  
Asynchronous version of socket.getaddrinfo().
coroutine loop.getnameinfo(sockaddr, flags=0)  
Asynchronous version of socket.getnameinfo().
loop.get_debug()  
Get the debug mode (bool) of the event loop. The default value is True if the environment variable PYTHONASYNCIODEBUG is set to a non-empty string, False otherwise.
loop.get_exception_handler()  
Return the current exception handler, or None if no custom exception handler was set.  New in version 3.5.2.
loop.get_task_factory()  
Return a task factory or None if the default one is in use.
loop.remove_signal_handler(sig)  
Remove the handler for the sig signal. Return True if the signal handler was removed, or False if no handler was set for the given signal. Availability: Unix.
loop.run_forever()  
Run the event loop until stop() is called. If stop() is called before run_forever() is called, the loop will poll the I/O selector once with a timeout of zero, run all callbacks scheduled in response to I/O events (and those that were already scheduled), and then exit. If stop() is called while run_forever() is running, the loop will run the current batch of callbacks and then exit. Note that new callbacks scheduled by callbacks will not run in this case; instead, they will run the next time run_forever() or run_until_complete() is called.
awaitable loop.run_in_executor(executor, func, *args)  
Arrange for func to be called in the specified executor. The executor argument should be an concurrent.futures.Executor instance. The default executor is used if executor is None. Example: import asyncio
import concurrent.futures

def blocking_io():
    # File operations (such as logging) can block the
    # event loop: run them in a thread pool.
    with open('/dev/urandom', 'rb') as f:
        return f.read(100)

def cpu_bound():
    # CPU-bound operations will block the event loop:
    # in general it is preferable to run them in a
    # process pool.
    return sum(i * i for i in range(10 ** 7))

async def main():
    loop = asyncio.get_running_loop()

    ## Options:

    # 1. Run in the default loop's executor:
    result = await loop.run_in_executor(
        None, blocking_io)
    print('default thread pool', result)

    # 2. Run in a custom thread pool:
    with concurrent.futures.ThreadPoolExecutor() as pool:
        result = await loop.run_in_executor(
            pool, blocking_io)
        print('custom thread pool', result)

    # 3. Run in a custom process pool:
    with concurrent.futures.ProcessPoolExecutor() as pool:
        result = await loop.run_in_executor(
            pool, cpu_bound)
        print('custom process pool', result)

asyncio.run(main())
 This method returns a asyncio.Future object. Use functools.partial() to pass keyword arguments to func.  Changed in version 3.5.3: loop.run_in_executor() no longer configures the max_workers of the thread pool executor it creates, instead leaving it up to the thread pool executor (ThreadPoolExecutor) to set the default.
loop.run_until_complete(future)  
Run until the future (an instance of Future) has completed. If the argument is a coroutine object it is implicitly scheduled to run as a asyncio.Task. Return the Future’s result or raise its exception.