You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2010/09/02 17:12:07 UTC

svn commit: r991969 - /incubator/thrift/trunk/lib/py/src/server/TServer.py

Author: bryanduxbury
Date: Thu Sep  2 15:12:06 2010
New Revision: 991969

URL: http://svn.apache.org/viewvc?rev=991969&view=rev
Log:
THRIFT-598. py: Allow Python's threading servers to use daemon threads

Patch: David Reiss

Modified:
    incubator/thrift/trunk/lib/py/src/server/TServer.py

Modified: incubator/thrift/trunk/lib/py/src/server/TServer.py
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/py/src/server/TServer.py?rev=991969&r1=991968&r2=991969&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/py/src/server/TServer.py (original)
+++ incubator/thrift/trunk/lib/py/src/server/TServer.py Thu Sep  2 15:12:06 2010
@@ -93,8 +93,9 @@ class TThreadedServer(TServer):
 
   """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 @@ class TThreadedServer(TServer):
       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 @@ class TThreadPoolServer(TServer):
 
   """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 @@ class TThreadPoolServer(TServer):
     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)