[Zodb-checkins] CVS: Packages/ZEO - forker.py:1.3
jeremy@digicool.com
jeremy@digicool.com
Tue, 8 May 2001 17:16:38 -0400 (EDT)
Update of /cvs-repository/Packages/ZEO/tests
In directory korak:/tmp/cvs-serv15308/tests
Modified Files:
forker.py
Log Message:
Add run_server() method and profile support from ZEO2
--- Updated File forker.py in package Packages/ZEO --
--- forker.py 2001/05/01 19:54:33 1.2
+++ forker.py 2001/05/08 21:16:37 1.3
@@ -1,11 +1,17 @@
"""Library for forking storage server and connecting client storage"""
import asyncore
+import atexit
import os
+import profile
import sys
+import time
+import types
import ThreadedAsync
import ZEO.ClientStorage, ZEO.StorageServer
+PROFILE = 0
+
class ZEOServerExit(asyncore.file_dispatcher):
"""Used to exit ZEO.StorageServer when run is done"""
@@ -36,24 +42,30 @@
rd, wr = os.pipe()
pid = os.fork()
if pid == 0:
- # in the child, run the storage server
- try:
- os.close(wr)
- ZEOServerExit(rd)
- serv = ZEO.StorageServer.StorageServer(addr, {'1':storage})
- asyncore.loop()
- storage.close()
- if domain == "AF_UNIX":
- os.unlink(addr)
- if cleanup:
- cleanup()
- finally:
- os._exit(0)
+ if PROFILE:
+ p = profile.Profile()
+ p.runctx("run_server(storage, addr, rd, wr)", globals(),
+ locals())
+ p.dump_stats("stats.s.%d" % os.getpid())
+ else:
+ run_server(storage, addr, rd, wr)
+ os._exit(0)
else:
os.close(rd)
return pid, ZEOClientExit(wr)
+
+def run_server(storage, addr, rd, wr):
+ # in the child, run the storage server
+ os.close(wr)
+ ZEOServerExit(rd)
+ serv = ZEO.StorageServer.StorageServer(addr, {'1':storage})
+ asyncore.loop()
+ storage.close()
+ if isinstance(addr, types.StringType):
+ os.unlink(addr)
-def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"):
+def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET",
+ storage_id="1"):
"""Setup ZEO client-server for storage.
Returns a ClientStorage instance and a ZEOClientExit instance.
@@ -71,6 +83,10 @@
raise ValueError, "bad domain: %s" % domain
pid, exit = start_zeo_server(storage, addr)
- s = ZEO.ClientStorage.ClientStorage(addr, debug=1, client=cache)
+ s = ZEO.ClientStorage.ClientStorage(addr, storage_id,
+ debug=1, client=cache)
+ if hasattr(s, 'is_connected'):
+ while not s.is_connected():
+ time.sleep(0.1)
return s, exit, pid