[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Make watchStart and watchMain global functions rather than classmethods,
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID 10bafcc750fb5553abfb5ac8196c4925c7aed034 # Parent 009eb32c0ae47ee021b82932f02b382f56a9519b Make watchStart and watchMain global functions rather than classmethods, meaning that we no longer need to prefix all the field accesses with cls. Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx> diff -r 009eb32c0ae4 -r 10bafcc750fb tools/python/xen/xend/xenstore/xswatch.py --- a/tools/python/xen/xend/xenstore/xswatch.py Tue Nov 15 18:09:30 2005 +++ b/tools/python/xen/xend/xenstore/xswatch.py Tue Nov 15 18:19:02 2005 @@ -13,47 +13,45 @@ class xswatch: - watchThread = None - xs = None - xslock = threading.Lock() - def __init__(self, path, fn, *args, **kwargs): self.path = path self.fn = fn self.args = args self.kwargs = kwargs - xswatch.watchStart() - xswatch.xs.watch(path, self) + watchStart() + xs.watch(path, self) - def watchStart(cls): - cls.xslock.acquire() - try: - if cls.watchThread: - return - cls.xs = xshandle() - cls.watchThread = threading.Thread(name="Watcher", - target=cls.watchMain) - cls.watchThread.setDaemon(True) - cls.watchThread.start() - finally: - cls.xslock.release() +watchThread = None +xs = None +xslock = threading.Lock() - watchStart = classmethod(watchStart) +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(cls): - while True: - try: - we = cls.xs.read_watch() - watch = we[1] - res = watch.fn(*watch.args, **watch.kwargs) - if not res: - cls.xs.unwatch(watch.path, watch) - except: - log.exception("read_watch failed") - # Ignore this exception -- there's no point throwing it - # further on because that will just kill the watcher thread, - # which achieves nothing. - - watchMain = classmethod(watchMain) +def watchMain(): + while True: + try: + we = xs.read_watch() + watch = we[1] + res = watch.fn(*watch.args, **watch.kwargs) + if not res: + xs.unwatch(watch.path, watch) + except: + log.exception("read_watch failed") + # Ignore this exception -- there's no point throwing it + # further on because that will just kill the watcher thread, + # which achieves nothing. _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |