Examples of aiomonitor usage¶
Below is a list of examples from aiomonitor/examples
Every example is a correct tiny python program.
Basic Usage¶
Basic example, starts monitor around loop.run_forever()
function:
import asyncio
import aiomonitor
loop = asyncio.get_event_loop()
with aiomonitor.start_monitor(loop=loop):
print("Now you can connect with: nc localhost 50101")
loop.run_forever()
aiohttp Example¶
Full feature example with aiohttp application:
import asyncio
import aiomonitor
from aiohttp import web
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))
with aiomonitor.start_monitor(loop=loop):
web.run_app(app, port=8090, host='localhost')
Any above examples compatible with uvloop, in fact aiomonitor test suite executed against asyncio and uvloop.