Debian Codegraph @

examples/monitor.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 """
3 monitor
4 ~~~~~~~
5
6 A simple monitor, which fires a callback each time a new domains
7 is introduced or released from XenStore.
8
9 :copyright: (c) 2011 by Selectel, see AUTHORS for more details.
10 """
11
12 import pyxs
13
14 with pyxs.monitor() as m:
15 m.watch(b"@introduceDomain", b"unused")
16 m.watch(b"@releaseDomain", b"unused")
17
18 for wpath, _token in m.wait():
19 # Funny thing is -- XenStored doesn't send us domid of the
20 # event target, so we have to get it manually, via ``xc``.
21 if wpath == b"@introduceDomain":
22 print("Hey, we got a new domain here!")
23 else:
24 print("Ooops, we lost him ...")