[Zodb-checkins] CVS: ZODB4/src/zodb/zeo/tests - zeoserver.py:1.4

Barry Warsaw barry@wooz.org
Tue, 7 Jan 2003 18:23:11 -0500


Update of /cvs-repository/ZODB4/src/zodb/zeo/tests
In directory cvs.zope.org:/tmp/cvs-serv6403

Modified Files:
	zeoserver.py 
Log Message:
Forward port from ZODB3, a suicide thread to make sure these processes
don't live forever.


=== ZODB4/src/zodb/zeo/tests/zeoserver.py 1.3 => 1.4 ===
--- ZODB4/src/zodb/zeo/tests/zeoserver.py:1.3	Fri Jan  3 16:53:35 2003
+++ ZODB4/src/zodb/zeo/tests/zeoserver.py	Tue Jan  7 18:23:08 2003
@@ -15,12 +15,14 @@
 
 import os
 import sys
+import time
 import errno
 import getopt
 import random
 import socket
 import logging
 import asyncore
+import threading
 
 import ZConfig.Context
 from zodb import config
@@ -102,8 +104,21 @@
         self._count -= 1
 
 
-def main():
+class Suicide(threading.Thread):
+    def __init__(self, addr):
+        threading.Thread.__init__(self)
+        self._adminaddr = addr
+
+    def run(self):
+        # If this process doesn't exit in 60 seconds, commit suicide
+        time.sleep(60)
+        from ZEO.tests.forker import shutdown_zeo_server
+        # XXX If the -k option was given to zeoserver, then the process will
+        # go away but the temp files won't get cleaned up.
+        shutdown_zeo_server(self._adminaddr)
+
 
+def main():
     # Initialize the logging module.
     import logging.config
     logging.basicConfig()
@@ -141,10 +156,11 @@
     # The rest of the args are hostname, portnum
     zeo_port = int(args[0])
     test_port = zeo_port + 1
+    test_addr = ('', test_port)
     try:
         logger.info('creating the test server, ro: %s, keep: %s',
                     ro_svr, keep)
-        t = ZEOTestServer(('', test_port), storage, keep)
+        t = ZEOTestServer(test_addr, storage, keep)
     except socket.error, e:
         if e[0] <> errno.EADDRINUSE: raise
         logger.info('addr in use, closing and exiting')
@@ -154,6 +170,11 @@
     addr = ('', zeo_port)
     logger.info('creating the storage server')
     serv = zodb.zeo.server.StorageServer(addr, {'1': storage}, ro_svr)
+    # Create daemon suicide thread
+    d = Suicide(test_addr)
+    d.setDaemon(1)
+    d.start()
+    # Loop for socket events
     logger.info('entering threadedasync loop')
     threadedasync.loop()