THRIFT-598. py: Allow Python's threading servers to use daemon threads

Patch: David Reiss

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@991969 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/server/TServer.py b/lib/py/src/server/TServer.py
index 6152911..8456e2d 100644
--- a/lib/py/src/server/TServer.py
+++ b/lib/py/src/server/TServer.py
@@ -93,8 +93,9 @@
 
   """Threaded server that spawns a new thread per each connection."""
 
-  def __init__(self, *args):
+  def __init__(self, *args, **kwargs):
     TServer.__init__(self, *args)
+    self.daemon = kwargs.get("daemon", False)
 
   def serve(self):
     self.serverTransport.listen()
@@ -102,6 +103,7 @@
       try:
         client = self.serverTransport.accept()
         t = threading.Thread(target = self.handle, args=(client,))
+        t.setDaemon(self.daemon)
         t.start()
       except KeyboardInterrupt:
         raise
@@ -128,10 +130,11 @@
 
   """Server with a fixed size pool of threads which service requests."""
 
-  def __init__(self, *args):
+  def __init__(self, *args, **kwargs):
     TServer.__init__(self, *args)
     self.clients = Queue.Queue()
     self.threads = 10
+    self.daemon = kwargs.get("daemon", False)
 
   def setNumThreads(self, num):
     """Set the number of worker threads that should be created"""
@@ -168,6 +171,7 @@
     for i in range(self.threads):
       try:
         t = threading.Thread(target = self.serveThread)
+        t.setDaemon(self.daemon)
         t.start()
       except Exception, x:
         logging.exception(x)