跳转到主要内容

异步控制台和asyncio接口

项目描述

异步控制台和asyncio接口

aioconsole 提供

  • 异步等价于 inputprintexeccode.interact

  • 运行异步Python控制台的交互循环

  • 使用 argparse 自定义和运行命令行界面

  • 通过 stream 支持而不是使用标准流来提供接口

  • apython 脚本,在运行时访问asyncio代码而不修改源代码

要求

  • Python >= 3.8

安装

aioconsole 可在 PyPIGitHub 上找到。以下两个命令都安装了 aioconsole 软件包和 apython 脚本。

$ pip3 install aioconsole   # from PyPI
$ python3 setup.py install  # or from the sources
$ apython -h
usage: apython [-h] [--serve [HOST:] PORT] [--no-readline]
               [--banner BANNER] [--locals LOCALS]
               [-m MODULE | FILE] ...

Run the given python file or module with a modified asyncio policy replacing
the default event loop with an interactive loop. If no argument is given, it
simply runs an asynchronous python console.

positional arguments:
  FILE                  python file to run
  ARGS                  extra arguments

optional arguments:
  -h, --help            show this help message and exit
  --serve [HOST:] PORT, -s [HOST:] PORT
                        serve a console on the given interface instead
  --no-readline         force readline disabling
  --banner BANNER       provide a custom banner
  --locals LOCALS       provide custom locals as a dictionary
  -m MODULE             run a python module

简单用法

以下示例演示了在控制台内使用 await

$ apython
Python 3.5.0 (default, Sep 7 2015, 14:12:03)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
---
This console is running in an asyncio event loop.
It allows you to wait for coroutines using the 'await' syntax.
Try: await asyncio.sleep(1, result=3, loop=loop)
---
>>> await asyncio.sleep(1, result=3)
# Wait one second...
3
>>>

文档

文档示例目录 中找到更多示例。

限制

与IPython或ptpython等现代控制台相比,由aioconsole提供的Python控制台功能相当有限。幸运的是,这些项目在多年的发展中获得了更大的asyncio支持。特别是,以下用例与aioconsole功能重叠:

联系

Vincent Michel: vxgmichel@gmail.com

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

aioconsole-0.8.0.tar.gz (60.7 kB 查看哈希值)

上传时间

构建分布

aioconsole-0.8.0-py3-none-any.whl (43.3 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面