簡體   English   中英

為什么我的控制台顯示來自try塊中引發的Thrift異常的堆棧跟蹤?

[英]Why does my console display a stack trace from a Thrift exception raised within a try block?

我的節儉客戶端當前未連接,因此對self.transport.open()的調用應超時,並且我的程序應繼續執行。 但是我想知道為什么超時會引發異常,為什么堆棧跟蹤會打印到控制台,以及這是否表明存在問題。

編碼:

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

和堆棧跟蹤:

->  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...

您使用以下命令打印活動記錄器

import logging
for key in logging.Logger.manager.loggerDict:
    print(key)

然后,對於與TSocket相關的記錄器,可以將調試級別設置為critical

logging.getLogger('thrift.transport.TSocket').setLevel(logging.CRITICAL)

要么

logging.getLogger('thrift.transport.TSocket').setLevel(logging.NOTSET)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM