WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Make watchStart and watchMain global functions rather th

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Make watchStart and watchMain global functions rather than classmethods,
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 15 Nov 2005 21:16:21 +0000
Delivery-date: Tue, 15 Nov 2005 21:18:51 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Make watchStart and watchMain global functions rather than classmethods,, Xen patchbot -unstable <=