X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=examples%2Fallwatcher.py;h=c215d20cb33ef66ac21e8ec63bf577428930c0ae;hb=a9180cca8165ab6396971a30e3063845a428dd5e;hp=6c549b47fb13bbacd819f007d938ee7b2b3a9cfe;hpb=edf3beda420d3a2c66d6ef8fe9b5e45a76d052b9;p=osm%2FN2VC.git diff --git a/examples/allwatcher.py b/examples/allwatcher.py index 6c549b4..c215d20 100644 --- a/examples/allwatcher.py +++ b/examples/allwatcher.py @@ -1,19 +1,32 @@ +""" +This example: + +1. Connects to the current model +2. Starts an AllWatcher +3. Prints all changes received from the AllWatcher +4. Runs forever (kill with Ctrl-C) + +""" import asyncio +import logging from juju.client.connection import Connection from juju.client import watcher - - -loop = asyncio.get_event_loop() -conn = loop.run_until_complete(Connection.connect_current()) +from juju import loop async def watch(): allwatcher = watcher.AllWatcher() + conn = await Connection.connect_current() allwatcher.connect(conn) while True: change = await allwatcher.Next() for delta in change.deltas: print(delta.deltas) -loop.run_until_complete(watch()) + +if __name__ == '__main__': + logging.basicConfig(level=logging.DEBUG) + # Run loop until the process is manually stopped (watch will loop + # forever). + loop.run(watch())