Skip to main content

aiomonitor adds monitor and python REPL capabilities for asyncio application

Project description

aiomonitor

https://travis-ci.org/jettify/aiomonitor.svg?branch=master https://codecov.io/gh/jettify/aiomonitor/branch/master/graph/badge.svg

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

Installation process is simple, just:

$ pip install aiomonitor

Example

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

Run tests

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

Requirements

CHANGES

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aiomonitor, version 0.0.1
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

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page