[Zodb-checkins] SVN: ZODB/trunk/src/ Bug Fixed:

Jim Fulton jim at zope.com
Thu Oct 8 13:50:10 EDT 2009


Log message for revision 104949:
  Bug Fixed:
    ZEO manages a separate thread for client network IO.  It created
    this thread on import, which caused problems for applications that
    implemented daemon behavior by forking.  Now, the client thread
    isn't created until needed.
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/ZEO/tests/testZEO.py
  U   ZODB/trunk/src/ZEO/zrpc/client.py
  U   ZODB/trunk/src/ZEO/zrpc/connection.py

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2009-10-08 17:29:44 UTC (rev 104948)
+++ ZODB/trunk/src/CHANGES.txt	2009-10-08 17:50:10 UTC (rev 104949)
@@ -2,6 +2,17 @@
  Change History
 ================
 
+3.9.2 (2009-10-??)
+==================
+
+Bugs Fixed
+----------
+
+- ZEO manages a separate thread for client network IO.  It created
+  this thread on import, which caused problems for applications that
+  implemented daemon behavior by forking.  Now, the client thread
+  isn't created until needed.
+
 3.9.1 (2009-10-01)
 ==================
 

Modified: ZODB/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py	2009-10-08 17:29:44 UTC (rev 104948)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py	2009-10-08 17:50:10 UTC (rev 104949)
@@ -52,6 +52,8 @@
 
 logger = logging.getLogger('ZEO.tests.testZEO')
 
+ZEO.zrpc.connection.start_client_thread()
+
 class DummyDB:
     def invalidate(self, *args):
         pass

Modified: ZODB/trunk/src/ZEO/zrpc/client.py
===================================================================
--- ZODB/trunk/src/ZEO/zrpc/client.py	2009-10-08 17:29:44 UTC (rev 104948)
+++ ZODB/trunk/src/ZEO/zrpc/client.py	2009-10-08 17:50:10 UTC (rev 104949)
@@ -24,12 +24,13 @@
 
 from ZEO.zrpc.log import log
 import ZEO.zrpc.trigger
-from ZEO.zrpc.connection import ManagedClientConnection
+from ZEO.zrpc.connection import ManagedClientConnection, start_client_thread
 
 class ConnectionManager(object):
     """Keeps a connection up over time"""
 
     def __init__(self, addrs, client, tmin=1, tmax=180):
+        start_client_thread()
         self.addrlist = self._parse_addrs(addrs)
         self.client = client
         self.tmin = min(tmin, tmax)

Modified: ZODB/trunk/src/ZEO/zrpc/connection.py
===================================================================
--- ZODB/trunk/src/ZEO/zrpc/connection.py	2009-10-08 17:29:44 UTC (rev 104948)
+++ ZODB/trunk/src/ZEO/zrpc/connection.py	2009-10-08 17:50:10 UTC (rev 104949)
@@ -52,15 +52,15 @@
 atexit.register(client_exit)
 
 def client_loop():
+    global client_running
+    client_running = True
+    client_exit_event.clear()
+
     map = client_map
-
     read = asyncore.read
     write = asyncore.write
     _exception = asyncore._exception
     loop_failures = 0
-    client_exit_event.clear()
-    global client_running
-    client_running = True
 
     while client_running and map:
         try:
@@ -153,9 +153,19 @@
 
     client_exit_event.set()
 
-client_thread = threading.Thread(target=client_loop, name=__name__)
-client_thread.setDaemon(True)
-client_thread.start()
+client_thread_lock = threading.Lock()
+client_thread = None
+def start_client_thread():
+    client_thread_lock.acquire()
+    try:
+        global client_thread
+        if client_thread is None:
+            client_thread = threading.Thread(target=client_loop, name=__name__)
+            client_thread.setDaemon(True)
+            client_thread.start()
+    finally:
+        client_thread_lock.release()
+
 #
 ##############################################################################
 



More information about the Zodb-checkins mailing list