Nir Soffer has uploaded a new change for review.
Change subject: sourceRouteThread: Encapsulate inotify thread
......................................................................
sourceRouteThread: Encapsulate inotify thread
sourceRouteThread defined a main function for the inotify thread, but
the thread was created and started from supervdsmServer main function.
This couple these modules, expose module implementation details, and
make both sourceRouteThread and supervdsmServer harder to understand and
maintain.
This patch move inotify thread creation boilerplate from supervdsmServer
main function to a start function in sourceRouteThread module. The
inotify thread main function is private now, unlikely to be used from
other modules by mistake.
A nice side effect is shortening the too-big-and-growing try-block in
supervdsmServer main.
Change-Id: I38e1d402ac1c1cd4de4c3e74910244b47e7977f0
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M vdsm/sourceRouteThread.py
M vdsm/supervdsmServer
2 files changed, 15 insertions(+), 7 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/23/22723/1
diff --git a/vdsm/sourceRouteThread.py b/vdsm/sourceRouteThread.py
index c913220..b7ba568 100644
--- a/vdsm/sourceRouteThread.py
+++ b/vdsm/sourceRouteThread.py
@@ -1,5 +1,6 @@
import logging
import os
+import threading
import pyinotify
@@ -10,6 +11,7 @@
SOURCE_ROUTES_FOLDER = P_VDSM_RUN + 'sourceRoutes'
configurator = Iproute2()
+_thread = None
class DHClientEventHandler(pyinotify.ProcessEvent):
@@ -42,7 +44,16 @@
self.process_IN_CLOSE_WRITE_filePath(event.pathname)
-def subscribeToInotifyLoop():
+def start():
+ global _thread
+ assert _thread is None
+ _thread = threading.Thread(target=_subscribeToInotifyLoop,
+ name='sourceRoute')
+ _thread.daemon = True
+ _thread.start()
+
+
+def _subscribeToInotifyLoop():
logging.debug("sourceRouteThread.subscribeToInotifyLoop started")
# Subscribe to pyinotify event
diff --git a/vdsm/supervdsmServer b/vdsm/supervdsmServer
index 408dc4e..b84db27 100755
--- a/vdsm/supervdsmServer
+++ b/vdsm/supervdsmServer
@@ -79,8 +79,8 @@
"%s-%s" + _UDEV_RULE_FILE_EXT
RUN_AS_TIMEOUT = config.getint("irs", "process_pool_timeout")
-
_running = True
+
class Timeout(RuntimeError):
pass
@@ -366,6 +366,7 @@
global _running
_running = False
+
def main(sockfile, pidfile=None):
log = logging.getLogger("SuperVdsm.Server")
@@ -414,11 +415,7 @@
log.debug("Started serving super vdsm object")
- _sourceRouteThread = threading.Thread(
- target=sourceRouteThread.subscribeToInotifyLoop,
- name='sourceRoute')
- _sourceRouteThread.daemon = True
- _sourceRouteThread.start()
+ sourceRouteThread.start()
while _running:
signal.pause()
--
To view, visit
http://gerrit.ovirt.org/22723
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I38e1d402ac1c1cd4de4c3e74910244b47e7977f0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>