Commit 032b6e96 authored by Jeremy Hylton's avatar Jeremy Hylton

Don't block forever is server is not up.

Refactor main() to report all errors and exit with non-zero status.
parent e6b721b8
...@@ -18,15 +18,35 @@ Options: ...@@ -18,15 +18,35 @@ Options:
You must specify either -p and -h or -U. You must specify either -p and -h or -U.
""" """
import getopt
import socket
import sys
import time
from ZEO.ClientStorage import ClientStorage from ZEO.ClientStorage import ClientStorage
def main(addr, storage, days): WAIT = 10 # wait no more than 10 seconds for client to connect
def connect(storage):
# The connect-on-startup logic that ZEO provides isn't too useful
# for this script. We'd like to client to attempt to startup, but
# fail if it can't get through to the server after a reasonable
# amount of time. There's no external support for this, so we'll
# expose the ZEO 1.0 internals. (consenting adults only)
t0 = time.time()
while t0 + WAIT > time.time():
storage._call.connect()
if storage._connected:
return
raise RuntimeError, "Unable to connect to ZEO server"
def pack(addr, storage, days):
cs = ClientStorage(addr, storage=storage, wait_for_server_on_startup=1) cs = ClientStorage(addr, storage=storage, wait_for_server_on_startup=1)
# _startup() is an artifact of the way ZEO 1.0 works. The # _startup() is an artifact of the way ZEO 1.0 works. The
# ClientStorage doesn't get fully initialized until registerDB() # ClientStorage doesn't get fully initialized until registerDB()
# is called. The only thing we care about, though, is that # is called. The only thing we care about, though, is that
# registerDB() calls _startup(). # registerDB() calls _startup().
cs._startup() connect(cs)
cs.pack(wait=1, days=days) cs.pack(wait=1, days=days)
def usage(exit=1): def usage(exit=1):
...@@ -34,11 +54,7 @@ def usage(exit=1): ...@@ -34,11 +54,7 @@ def usage(exit=1):
print " ".join(sys.argv) print " ".join(sys.argv)
sys.exit(exit) sys.exit(exit)
if __name__ == "__main__": def main():
import getopt
import socket
import sys
host = None host = None
port = None port = None
unix = None unix = None
...@@ -70,4 +86,11 @@ if __name__ == "__main__": ...@@ -70,4 +86,11 @@ if __name__ == "__main__":
usage() usage()
addr = host, port addr = host, port
main(addr, storage, days) pack(addr, storage, days)
if __name__ == "__main__":
try:
main()
except Exception, err:
print err
sys.exit(1)
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