[Zodb-checkins] CVS: Packages/ZEO - forker.py:1.1.2.2 multi.py:1.1.2.3
jeremy@digicool.com
jeremy@digicool.com
Tue, 1 May 2001 14:43:54 -0400 (EDT)
Update of /cvs-repository/Packages/ZEO/tests
In directory korak:/tmp/cvs-serv2759/tests
Modified Files:
Tag: ZEO-ZRPC-Dev
forker.py multi.py
Log Message:
Refactor forker so that it can be used to start StorageServer without
starting ClientStorage.
forker.py: Add start_zeo_server() function called by start_zeo()
multi.py: Use start_zeo_server() and the ZEOClientExit object
--- Updated File forker.py in package Packages/ZEO --
--- forker.py 2001/04/27 21:03:36 1.1.2.1
+++ forker.py 2001/05/01 18:43:53 1.1.2.2
@@ -32,23 +32,7 @@
def close(self):
os.write(self.pipe, "done")
-def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"):
- """Setup ZEO client-server for storage.
-
- Returns a ClientStorage instance and a ZEOClientExit instance.
-
- XXX Don't know if os.pipe() will work on Windows.
- """
-
- if domain == "AF_INET":
- import random
- addr = '', random.randrange(2000, 3000)
- elif domain == "AF_UNIX":
- import tempfile
- addr = tempfile.mktemp()
- else:
- raise ValueError, "bad domain: %s" % domain
-
+def start_zeo_server(storage, addr):
rd, wr = os.pipe()
pid = os.fork()
if pid == 0:
@@ -67,6 +51,26 @@
os._exit(0)
else:
os.close(rd)
- s = ZEO.ClientStorage.ClientStorage(addr, debug=1, client=cache)
- return s, ZEOClientExit(wr), pid
+ return pid, ZEOClientExit(wr)
+
+def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"):
+ """Setup ZEO client-server for storage.
+
+ Returns a ClientStorage instance and a ZEOClientExit instance.
+
+ XXX Don't know if os.pipe() will work on Windows.
+ """
+
+ if domain == "AF_INET":
+ import random
+ addr = '', random.randrange(2000, 3000)
+ elif domain == "AF_UNIX":
+ import tempfile
+ addr = tempfile.mktemp()
+ else:
+ raise ValueError, "bad domain: %s" % domain
+
+ pid, exit = start_zeo_server(storage, addr)
+ s = ZEO.ClientStorage.ClientStorage(addr, debug=1, client=cache)
+ return s, exit, pid
--- Updated File multi.py in package Packages/ZEO --
--- multi.py 2001/04/25 22:50:38 1.1.2.2
+++ multi.py 2001/05/01 18:43:53 1.1.2.3
@@ -3,6 +3,7 @@
import ZODB, ZODB.DB, ZODB.FileStorage, ZODB.POSException
import Persistence
import PersistentMapping
+from ZEO.tests import forker
import asyncore
import os
@@ -48,16 +49,9 @@
return fs
def start_server(addr):
- pid = os.fork()
- if pid == 0:
- import ZEO.StorageServer
- storage = init_storage()
- server = ZEO.StorageServer.StorageServer(addr, {'1': storage})
- print "Server ready:", os.getpid()
- asyncore.loop()
- os._exit(0)
- else:
- return pid
+ storage = init_storage()
+ pid, exit = forker.start_zeo_server(storage, addr)
+ return pid, exit
def start_client(addr):
pid = os.fork()
@@ -123,7 +117,7 @@
print "Main process:", os.getpid()
addr = tempfile.mktemp()
t0 = time.time()
- server_pid = start_server(addr)
+ server_pid, server = start_server(addr)
t1 = time.time()
pids = [start_client(addr) for i in range(CLIENTS)]
for pid in pids:
@@ -136,7 +130,7 @@
except os.error, err:
print "waitpid(%s) failed: %s" % (repr(pid), err)
t2 = time.time()
- shutdown_server(addr)
+ server.close()
os.waitpid(server_pid, 0)
# XXX Should check that the results are consistent!