Mein Sparsamkeitsklient ist zurzeit nicht verbunden, also sollte der Anruf zu self.transport.open()
Timeout sein und meine Programmausführung sollte fortfahren, wie es tut. Aber ich möchte wissen, warum die Zeitüberschreitung eine Ausnahme auslöst, warum der Stack-Trace zur Konsole druckt und ob dies auf ein Problem hinweist.Warum zeigt meine Konsole einen Stack-Trace von einer Thrift-Ausnahme an, die in einem try-Block ausgelöst wurde?
Der Code:
def connect(self, url=None):
"""Attempt to connect to supervisor Thrift server"""
if conf.TESTING:
return
try:
self.url = url if url is not None else self.url
self.socket = TSocket.TSocket(self.url, constants.kSupervisorPort)
self.socket.setTimeout(1000)
self.transport = TTransport.TBufferedTransport(self.socket)
self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
self.client = Supervisor.Client(self.protocol)
log.warning("...Im about to raise an exception from inside a try block!")
self.transport.open()
self.connected = True
log.info('[TaskStateClient] Connected at url: ' + self.url)
except Exception:
log.warning("...and now Im handling the raised exception...")
Und der Stack-Trace:
-> Running
python app.py
werkzeug : INFO * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
root : WARNING ...Im about to raise an exception from inside a try block!
thrift.transport.TSocket: INFO Could not connect to ('192.168.1.219', 9002)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 104, in open
handle.connect(sockaddr)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
timeout: timed out
thrift.transport.TSocket: ERROR Could not connect to any of [('192.168.1.219', 9002)]
root : WARNING ...and now Im handling the raised exception...
Ist das Programm zu stoppen? Sind Sie nicht in irgendeiner Art von _Debug_-Modus und der Ausnahme-Traceback wird nur angezeigt? Anscheinend (nach dem Lesen der Ausgabe) scheint das der Fall zu sein: "_root: WARNING ... Ich bin im Begriff, eine Ausnahme innerhalb eines try-Blocks auszulösen! _". – CristiFati
Die Programmausführung stoppt nicht. Das Traceback wird sowohl im Debug-Modus als auch im Debug-Modus generiert, und es werden keine weiteren Tracebacks generiert (obwohl andere Ausnahmen behandelt werden). Diese Warnung stammt von mir - siehe die log.warning-Zeile im try-Block meines Codes. Danke fürs schauen! –
Dann glaube ich nicht, dass es ein Problem gibt. Ich habe _trift_ noch nie benutzt, aber ich denke, es zeigt nur die Ausnahme an (auch wenn es abgefangen wurde), weil es etwas verhindert hat, aber ich bin mir sicher, dass dies über eine Einstellung unterdrückt werden kann. – CristiFati