0

に例外がある場合memcache.Client、例外をキャプチャできますが、mc.getstatsそれでも実行できます。例外が発生したときにメインを停止するにはどうすればよいですか?

def main():
    if 'host' not in dir():
        host = '127.0.0.1'
    if 'port' not in dir():
        port = '11211'

    server = host + ':' + port

    try:
        mc = memcache.Client([server], debug=1,socket_timeout=3)
        result = mc.get_stats()
        mcstat = result[0][0]
        print mcstat
    except Exception,e:
        print e
        sys.exit(3)

if __name__ == "__main__":
    try:
        main()
    except:
        sys.exit(2)
4

1 に答える 1

0
import memcache
import sys


def main():
    host = "127.0.0.1"
    port = 11211

my_server = "{}:{}".format(host, port)

try:
    mc = memcache.Client(
       my_server   #<**** Should be an array
    )

    result = mc.get_stats()
    mcstat = result[0][0]
    print mcstat
except ValueError, e:
    print "Mission control: There was a problem..."
    print e
    sys.exit(3)

--output:--
Mission control: There was a problem...
Unable to parse connection string: "1"
于 2013-09-13T06:42:04.710 に答える