asyncutils.config

Set up some module-global state and sentinels, and expose some user-specified flags.

Attributes

basic_repl

Whether the user specified not to use the functions from _pyrepl to run the console.

debug

A global instance of the debugging context manager. Initially entered if and only if the user specified -d or --debug when starting the program.

loaded_all

Whether all submodules of this module have been loaded.

logging_to

The name (path; possibly relative) of the log file currently used by this library as a string, with four exceptions:

max_memerrs

Maximum number of memory errors that can occur before the console automatically exits. Negative if and only if there is no maximum.

pdb

Whether the user specified to drop into the debugger on an unhandled exception in the REPL console.

silent

Whether the user requested to run the program with no banner and exit message in the REPL.

Classes

Executor

A class that implements the PEP 3148 executor interface.

debugging

A context manager used to enter and exit debug mode, ensuring restoration of the original level if the level has not been modified externally within the context using set_logger_level().

Functions

get_past_logs(→ str)

Return all stored logs as a string. Logs are only stored if asyncutils was started with -l MEMORY, otherwise an empty string is returned.

set_logger_level(→ None)

Set the level of the module-global logger to level.

Module Contents

class asyncutils.config.Executor

Bases: concurrent.futures._base.Executor, asyncutils._internal.types.PartialInterface

A class that implements the PEP 3148 executor interface.

Note

The exact class is determined at runtime by command-line arguments.

Tip

Since instances of this class are only ever passed into run_in_executor(), nothing stops you from monkey-patching the event loop itself or policy thereof, and using a custom class that does not follow the interface, but that may be too hacky and fragile.

Tip

If you know your application only uses a specific executor, import this symbol at runtime and import the actual class in the stub or in an if TYPE_CHECKING: block where applicable to help type checkers.

class asyncutils.config.debugging[source]

A context manager used to enter and exit debug mode, ensuring restoration of the original level if the level has not been modified externally within the context using set_logger_level().

__enter__() Self[source]

Start debugging. More output is produced; where to depends on the user’s own configuration, accessible via logging_to and debug.level.

__exit__(exc_typ: asyncutils._internal.types.ExcType, exc_val: BaseException, exc_tb: types.TracebackType, /) None[source]
__exit__(exc_typ: None, exc_val: None, exc_tb: None, /) None

Stop debugging, restoring the output to its previous level if appropriate.

property entered: bool

Whether the context is entered.

property level: int

The current level of the asyncutils logger, as an integer.

property orig_level: int | None

The original logger level as an integer, before this context was entered, or None if it was not.

property orig_name: str | None

The original logger level name as a string, before this context was entered, or None if it was not.

asyncutils.config.get_past_logs() str

Return all stored logs as a string. Logs are only stored if asyncutils was started with -l MEMORY, otherwise an empty string is returned.

asyncutils.config.set_logger_level(level: int) None

Set the level of the module-global logger to level.

asyncutils.config.basic_repl: Final[bool]

Whether the user specified not to use the functions from _pyrepl to run the console.

asyncutils.config.debug: Final[debugging]

A global instance of the debugging context manager. Initially entered if and only if the user specified -d or --debug when starting the program.

asyncutils.config.loaded_all: Final[bool]

Whether all submodules of this module have been loaded.

asyncutils.config.logging_to: Final[str]

The name (path; possibly relative) of the log file currently used by this library as a string, with four exceptions:

  • 'NULL': no logging is taking place

  • 'MEMORY': the logs are not going to a physical file but can be retrieved by get_past_logs()

  • 'STDOUT': logging is going to sys.stdout

  • 'STDERR': logging is going to sys.stderr (following the default and fallback behaviour of logging)

asyncutils.config.max_memerrs: Final[int]

Maximum number of memory errors that can occur before the console automatically exits. Negative if and only if there is no maximum.

asyncutils.config.pdb: Final[bool]

Whether the user specified to drop into the debugger on an unhandled exception in the REPL console.

asyncutils.config.silent: Final[bool]

Whether the user requested to run the program with no banner and exit message in the REPL.