Python sys.exit 无法打破主



当我在memcache.Client中有 except 时,我可以捕获异常,但mc.getstats仍然是 exec,当有异常时我应该怎么做才能停止主

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)
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"

相关内容

  • 没有找到相关文章

最新更新