direct-io.hg
changeset 7822:10bafcc750fb
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@xensource.com>
meaning that we no longer need to prefix all the field accesses with cls.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@leeni.uk.xensource.com |
---|---|
date | Tue Nov 15 19:19:02 2005 +0100 (2005-11-15) |
parents | 009eb32c0ae4 |
children | 9c7aeec94f8a 725bf42d4713 |
files | tools/python/xen/xend/xenstore/xswatch.py |
line diff
1.1 --- a/tools/python/xen/xend/xenstore/xswatch.py Tue Nov 15 19:09:30 2005 +0100 1.2 +++ b/tools/python/xen/xend/xenstore/xswatch.py Tue Nov 15 19:19:02 2005 +0100 1.3 @@ -13,47 +13,45 @@ from xen.xend.XendLogging import log 1.4 1.5 class xswatch: 1.6 1.7 - watchThread = None 1.8 - xs = None 1.9 - xslock = threading.Lock() 1.10 - 1.11 def __init__(self, path, fn, *args, **kwargs): 1.12 self.path = path 1.13 self.fn = fn 1.14 self.args = args 1.15 self.kwargs = kwargs 1.16 - xswatch.watchStart() 1.17 - xswatch.xs.watch(path, self) 1.18 + watchStart() 1.19 + xs.watch(path, self) 1.20 1.21 1.22 - def watchStart(cls): 1.23 - cls.xslock.acquire() 1.24 - try: 1.25 - if cls.watchThread: 1.26 - return 1.27 - cls.xs = xshandle() 1.28 - cls.watchThread = threading.Thread(name="Watcher", 1.29 - target=cls.watchMain) 1.30 - cls.watchThread.setDaemon(True) 1.31 - cls.watchThread.start() 1.32 - finally: 1.33 - cls.xslock.release() 1.34 +watchThread = None 1.35 +xs = None 1.36 +xslock = threading.Lock() 1.37 1.38 - watchStart = classmethod(watchStart) 1.39 +def watchStart(): 1.40 + global watchThread 1.41 + global xs 1.42 + 1.43 + xslock.acquire() 1.44 + try: 1.45 + if watchThread: 1.46 + return 1.47 + xs = xshandle() 1.48 + watchThread = threading.Thread(name="Watcher", target=watchMain) 1.49 + watchThread.setDaemon(True) 1.50 + watchThread.start() 1.51 + finally: 1.52 + xslock.release() 1.53 1.54 1.55 - def watchMain(cls): 1.56 - while True: 1.57 - try: 1.58 - we = cls.xs.read_watch() 1.59 - watch = we[1] 1.60 - res = watch.fn(*watch.args, **watch.kwargs) 1.61 - if not res: 1.62 - cls.xs.unwatch(watch.path, watch) 1.63 - except: 1.64 - log.exception("read_watch failed") 1.65 - # Ignore this exception -- there's no point throwing it 1.66 - # further on because that will just kill the watcher thread, 1.67 - # which achieves nothing. 1.68 - 1.69 - watchMain = classmethod(watchMain) 1.70 +def watchMain(): 1.71 + while True: 1.72 + try: 1.73 + we = xs.read_watch() 1.74 + watch = we[1] 1.75 + res = watch.fn(*watch.args, **watch.kwargs) 1.76 + if not res: 1.77 + xs.unwatch(watch.path, watch) 1.78 + except: 1.79 + log.exception("read_watch failed") 1.80 + # Ignore this exception -- there's no point throwing it 1.81 + # further on because that will just kill the watcher thread, 1.82 + # which achieves nothing.