event_loops module

This is a collection of my initial experimentation with the asyncio modules. These have proven particularly interesting, especially given the complex API Windows uses around multiprocessing, and as a result, don’t entirely seem well supported in the python standard library yet.

Asyncio operations

Here’s a useful asyncio function:

def extract_stack(f=None, limit=None):
    Replacement for traceback.extract_stack() that only does the
    necessary work for asyncio debug mode.

Reduced Imports

Todo

Bugs

What the hell is this?:

In [29]: %edit event_loops.py
Editing... done. Executing edited code...
ModuleNotFoundError: No module named '_overlapped'

> /home/farbuntu/miniconda3/envs/working/lib/python3.8/asyncio/windows_events.py(3)<module>()
    1 # "Selector and proactor event loops for Windows.
    2
----> 3 import _overlapped
    4 import _winapi
    5 import errno

Autogenerated docs for the event loop

children()[source][source]

Return multiprocessing.active_children. Simply to save the typing.

enable_multiprocessing_logging(level=50)[source][source]

Log to stderr.

async system_command(command_to_run)[source][source]

Run a system command using prompt_toolkit’s run_system_command.

Examples

In [40]: await system_command('ls')  # +NORMALIZE_WHITESPACE
01_rehashx.py       20_aliases.py        31_yank_last_arg.py
36_ptutils.py     cscope.out  05_log.py           21_fzf.py
kb.py              41_numpy_init.py  event_loops.py 06_help_helpers.py
22_alias_manager.py  bottom_toolbar.py  43_matplotlib.py
interpreter.py 10_envvar.py        23_git_commands.py   34_completion.py
__init__.py       repralias.py
clipboard.py     30_readline.py       35_lexer.py
__main__.py       tags
>>> await _ip.pt_app.app.run_async(print('hi'))
hi

Whoo!

initialize_kernel()[source][source]

Initialize a curio.Kernel.

async kernel_run(command, kernel)[source][source]
async subproc(command)[source][source]