X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=examples%2Fallwatcher.py;h=c215d20cb33ef66ac21e8ec63bf577428930c0ae;hp=ecd6e82cd730bfde280f4991e651cccbe68f8edb;hb=65d71ab71ce1aaf9ca3aeeee7dd6cb8793278b3e;hpb=5cf8d29d1ec5ff9360920dd831ff6ead145e3d11 diff --git a/examples/allwatcher.py b/examples/allwatcher.py index ecd6e82..c215d20 100644 --- a/examples/allwatcher.py +++ b/examples/allwatcher.py @@ -12,10 +12,12 @@ import logging from juju.client.connection import Connection from juju.client import watcher +from juju import loop async def watch(): allwatcher = watcher.AllWatcher() + conn = await Connection.connect_current() allwatcher.connect(conn) while True: change = await allwatcher.Next() @@ -23,7 +25,8 @@ async def watch(): print(delta.deltas) -logging.basicConfig(level=logging.DEBUG) -loop = asyncio.get_event_loop() -conn = loop.run_until_complete(Connection.connect_current()) -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())