connection_workflow.AMQPConnectorStackTimeout 来自 BlockingConnection

connection_workflow.AMQPConnectorStackTimeout from BlockingConnection

pika BlockingConnection 尝试失败(pika 版本 1.0.0)。应用程序日志中显示的异常 - adapters.utils.connection_workflow.AMQPConnectorStackTimeout - 似乎不是 pika.exceptions.

中的任何异常

pika 难道不应该在向调用者显示之前将诸如此类的内部异常转换为 pika.exceptions 中的异常之一吗?

如果不是,我应该如何枚举 pika 可能引发的所有可能异常,以便我可以决定调用者可以处理哪些,不应该尝试处理哪些? (本质上,调用者需要决定是在出现不可恢复的异常时退出,还是在条件可能是暂时的情况下重试。)

可能是我理解错了应用日志,如下:

2019-04-26T11:33:29.880310567Z ERROR:pika.adapters.utils.connection_workflow:Timeout while setting up AMQP to '█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False
2019-04-26T11:33:29.880880966Z ERROR:pika.adapters.utils.connection_workflow:AMQPConnector - reporting failure: AMQPConnectorAMQPHandshakeError: AMQPConnectorStackTimeout("Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', █)); ssl=False",)
2019-04-26T11:33:29.881053365Z ERROR:pika.adapters.utils.connection_workflow:AMQP connection workflow failed: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorAMQPHandshakeError: AMQPConnectorStackTimeout("Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False",); first exception - None.
2019-04-26T11:33:29.881150165Z ERROR:pika.adapters.utils.connection_workflow:AMQPConnectionWorkflow - reporting failure: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorAMQPHandshakeError: AMQPConnectorStackTimeout("Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False",); first exception - None
2019-04-26T11:33:29.881503064Z ERROR:pika.adapters.blocking_connection:Connection workflow failed: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorAMQPHandshakeError: AMQPConnectorStackTimeout("Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False",); first exception - None
2019-04-26T11:33:29.882705661Z ERROR:pika.adapters.blocking_connection:Error in _create_connection().
2019-04-26T11:33:29.882720061Z Traceback (most recent call last):
2019-04-26T11:33:29.882724561Z   File "/usr/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 451, in _create_connection
2019-04-26T11:33:29.882728961Z     raise self._reap_last_connection_workflow_error(error)
2019-04-26T11:33:29.882732761Z pika.adapters.utils.connection_workflow.AMQPConnectorStackTimeout: Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False
2019-04-26T11:33:29.883257859Z ERROR:root:AMQPConnectorStackTimeout Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False
2019-04-26T11:33:29.883273859Z Traceback (most recent call last):
2019-04-26T11:33:29.883278359Z   File "main.py", line 143, in <module>
2019-04-26T11:33:29.883282559Z     main()
2019-04-26T11:33:29.883286259Z   File "main.py", line 118, in main
2019-04-26T11:33:29.883290059Z     with pika.BlockingConnection(parameters=pika.URLParameters(██████████)) as connection:
2019-04-26T11:33:29.883293959Z   File "/usr/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 360, in __init__
2019-04-26T11:33:29.883307559Z     self._impl = self._create_connection(parameters, _impl_class)
2019-04-26T11:33:29.883311659Z   File "/usr/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 451, in _create_connection
2019-04-26T11:33:29.883315459Z     raise self._reap_last_connection_workflow_error(error)
2019-04-26T11:33:29.883319059Z pika.adapters.utils.connection_workflow.AMQPConnectorStackTimeout: Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False
2019-04-26T11:33:29.883323159Z Traceback (most recent call last):
2019-04-26T11:33:29.883326759Z   File "main.py", line 143, in <module>
2019-04-26T11:33:29.883465559Z     main()
2019-04-26T11:33:29.883473059Z   File "main.py", line 118, in main
2019-04-26T11:33:29.883635558Z     with pika.BlockingConnection(parameters=pika.URLParameters(██████████)) as connection:
2019-04-26T11:33:29.883650458Z   File "/usr/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 360, in __init__
2019-04-26T11:33:29.883894657Z     self._impl = self._create_connection(parameters, _impl_class)
2019-04-26T11:33:29.883902657Z   File "/usr/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 451, in _create_connection
2019-04-26T11:33:29.884212657Z     raise self._reap_last_connection_workflow_error(error)
2019-04-26T11:33:29.884222357Z pika.adapters.utils.connection_workflow.AMQPConnectorStackTimeout: Timeout during AMQP handshake'█.█.█.█'/(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '█.█.█.█', ('█.█.█.█', ████)); ssl=False

我又遇到了这个问题,发现了我自己的问题:-)

文档似乎有点缺乏,但 pika.adapters.utils.connection_workflow 中有一个完整的异常层次结构,基础 class 是 AMQPConnectorException.

答案似乎是浏览此模块源以查看应处理哪些异常。