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.

Source Distribution

aiomonitor-0.0.1.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file aiomonitor-0.0.1.tar.gz.

File metadata

  • Download URL: aiomonitor-0.0.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiomonitor-0.0.1.tar.gz
Algorithm Hash digest
SHA256 102669079dd672d983238ef0ef3da2d19d545012eaa23991bbf8131227cf8720
MD5 509530e2c6804e30b7c2ca227e4d6236
BLAKE2b-256 f9e5fed2dc5ac31ca0c6f5a829e6acd223485912b11470c1cf9c4c2420d78dc4

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page