1
# Copyright (C) 2005 Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
2
# Copyright (C) 2005 XenSource Ltd
4
# This file is subject to the terms and conditions of the GNU General
5
# Public License. See the file "COPYING" in the main directory of
6
# this archive for more details.
10
from xen.xend.xenstore.xsutil import xshandle
16
# Create a watch on the given path in the store. The watch will fire
17
# immediately, then subsequently each time the watched path is changed,
18
# until the watch is deregistered, either by the return value from the
19
# watch callback being False, or by an explicit call to unwatch.
21
# @param fn The function to be called when the watch fires. This function
22
# should take the path that has changed as its first argument, followed by
23
# the extra arguments given to this constructor, if any. It should return
24
# True if the watch is to remain registered, or False if it is to be
27
def __init__(self, path, fn, *args, **kwargs):
37
xs.unwatch(self.path, self)
42
xslock = threading.Lock()
53
watchThread = threading.Thread(name="Watcher", target=watchMain)
54
watchThread.setDaemon(True)
65
res = watch.fn(we[0], *watch.args, **watch.kwargs)
69
except RuntimeError, exn:
70
if exn.args[0] == errno.ENOENT:
71
# The watch has already been unregistered -- that's
78
# Ignore this exception -- there's no point throwing it
79
# further on because that will just kill the watcher thread,
80
# which achieves nothing.