⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xswatch.py

📁 xen虚拟机源代码安装包
💻 PY
字号:
# Copyright (C) 2005 Christian Limpach <Christian.Limpach@cl.cam.ac.uk># Copyright (C) 2005 XenSource Ltd# This file is subject to the terms and conditions of the GNU General# Public License.  See the file "COPYING" in the main directory of# this archive for more details.import errnoimport threadingfrom xen.xend.xenstore.xsutil import xshandleclass xswatch:    ##    # Create a watch on the given path in the store.  The watch will fire    # immediately, then subsequently each time the watched path is changed,    # until the watch is deregistered, either by the return value from the    # watch callback being False, or by an explicit call to unwatch.    #    # @param fn The function to be called when the watch fires.  This function    # should take the path that has changed as its first argument, followed by    # the extra arguments given to this constructor, if any.  It should return    # True if the watch is to remain registered, or False if it is to be    # deregistered.    #    def __init__(self, path, fn, *args, **kwargs):        self.path = path        self.fn = fn        self.args = args        self.kwargs = kwargs        watchStart()        xs.watch(path, self)    def unwatch(self):        xs.unwatch(self.path, self)watchThread = Nonexs = Nonexslock = threading.Lock()def watchStart():    global watchThread    global xs        xslock.acquire()    try:        if watchThread:            return        xs = xshandle()        watchThread = threading.Thread(name="Watcher", target=watchMain)        watchThread.setDaemon(True)        watchThread.start()    finally:        xslock.release()def watchMain():    while True:        try:            we = xs.read_watch()            watch = we[1]            res = watch.fn(we[0], *watch.args, **watch.kwargs)            if not res:                try:                    watch.unwatch()                except RuntimeError, exn:                    if exn.args[0] == errno.ENOENT:                        # The watch has already been unregistered -- that's                        # fine.                        pass                    else:                        raise        except:            pass            # Ignore this exception -- there's no point throwing it            # further on because that will just kill the watcher thread,            # which achieves nothing.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -