Commit d0fca77f authored by Barry Warsaw's avatar Barry Warsaw

Create a little Suicide thread so that if the parent process exits

(i.e. via ctrl-C) before it has a chance to make the killer connect,
these zeoserver processes will eventually go away (and clean up their
temp files).
parent ea54aa2b
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
import os import os
import sys import sys
import time
import errno import errno
import getopt import getopt
import random import random
import socket import socket
import asyncore import asyncore
import threading
import ThreadedAsync.LoopCallback import ThreadedAsync.LoopCallback
import ZConfig.Context import ZConfig.Context
...@@ -108,6 +110,18 @@ class ZEOTestServer(asyncore.dispatcher): ...@@ -108,6 +110,18 @@ class ZEOTestServer(asyncore.dispatcher):
self._count -= 1 self._count -= 1
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
shutdown_zeo_server(self._adminaddr)
def main(): def main():
label = 'zeoserver:%d' % os.getpid() label = 'zeoserver:%d' % os.getpid()
log(label, 'starting') log(label, 'starting')
...@@ -140,9 +154,10 @@ def main(): ...@@ -140,9 +154,10 @@ def main():
# The rest of the args are hostname, portnum # The rest of the args are hostname, portnum
zeo_port = int(args[0]) zeo_port = int(args[0])
test_port = zeo_port + 1 test_port = zeo_port + 1
test_addr = ('', test_port)
try: try:
log(label, 'creating the test server, ro: %s, keep: %s', ro_svr, keep) log(label, '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: except socket.error, e:
if e[0] <> errno.EADDRINUSE: raise if e[0] <> errno.EADDRINUSE: raise
log(label, 'addr in use, closing and exiting') log(label, 'addr in use, closing and exiting')
...@@ -155,6 +170,11 @@ def main(): ...@@ -155,6 +170,11 @@ def main():
addr, {'1': storage}, ro_svr, addr, {'1': storage}, ro_svr,
invalidation_queue_size=invalidation_queue_size, invalidation_queue_size=invalidation_queue_size,
transaction_timeout=transaction_timeout) transaction_timeout=transaction_timeout)
# Create daemon suicide thread
d = Suicide(test_addr)
d.setDaemon(1)
d.start()
# Loop for socket events
log(label, 'entering ThreadedAsync loop') log(label, 'entering ThreadedAsync loop')
ThreadedAsync.LoopCallback.loop() ThreadedAsync.LoopCallback.loop()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment