aiomonitor adds monitor and python REPL capabilities for asyncio application
aiomonitor is Python 3.5+ module that adds monitor and cli capabilities for asyncio application. Idea and code borrowed from curio project. Task monitor that runs concurrently to the asyncio loop (or fast drop in replacement uvloop) in a separate thread. This can inspect the loop and provide debugging capabilities.
Library provides an python console using aioconsole library, it is possible to execute asynchronous command inside your running application.
Installation process is simple, just:
$ pip install aiomonitor
Monitor has context manager interface:
from aiomonitor import Monitor loop = asyncio.get_event_loop() with Monitor(loop=loop): loop.run_forever()
Now from separate terminal it is possible to connect to the application:
$ nc localhost 50101
or using included python client:
$ python -m aiomonitor.cli
Full example in aiohttp application:
import asyncio from aiohttp import web from aiomonitor import Monitor async def simple(request): loop = request.app.loop print('Start sleeping') await asyncio.sleep(100, loop=loop) return web.Response(text="Simple answer") async def init(loop): app = web.Application(loop=loop) app.router.add_get('/simple', simple) return app loop = asyncio.get_event_loop() app = loop.run_until_complete(init(loop)) # init monitor just befor run_app with Monitor(loop=loop): web.run_app(app, port=8090, host='localhost')
And now one can connect with same command as in previous example:
$ nc localhost 50101
For testing purposes you need to install development requirements:
$ pip install -r requirements-dev.txt $ pip install -e .
Then just execute tests with coverage:
$ make cov
To run individual use following command:
$ py.test -sv tests/test_monitor.py -k test_name
- Initial release.
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size aiomonitor-0.0.1.tar.gz (6.0 kB)||File type Source||Python version None||Upload date||Hashes View hashes|