当我有一个except in时memcache.Client
,我可以捕获异常,但mc.getstats
仍然是exec,当有异常时我应该怎么做才能停止main?
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)