在长时间运行的配置单元插入查询期间“TSocket read 0 bytes”

2024-05-15 20:55:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用pyhive0.6.1在配置单元中运行一个长ish insert查询,它在运行大约5分钟后失败,并返回thrift.transport.TTransport.TTransportException: TSocket read 0 bytes。在服务器端,查询一直在运行,直到成功完成。我对快速查询没有这个问题。在

我不能在Mac上用相同的python版本在本地复制它:代码正确地等待直到查询完成。发生这种情况的环境是基于python:3.6-slim。除此之外,我正在安装libsasl2 dev和libsasl2 modules包,以及pyhive[hive]python包。在

有什么线索吗?提前谢谢。在

我使用的代码是:

import contextlib
from pyhive.hive import connect

def get_conn():
    return connect(
        host='my-host',
        port=10000,
        auth='NONE',
        username='username',
        database='database'
    )

with contextlib.closing(get_conn()) as conn, \
        contextlib.closing(conn.cursor()) as cur:
    cur.execute('My long insert statement')

这是完整的回溯

^{pr2}$

Tags: 代码importhostgetasconnectusernameconn
1条回答
网友
1楼 · 发布于 2024-05-15 20:55:08

代码引发的异常如下:

  def read(self, sz):
        try:
            buff = self.handle.recv(sz)
        except socket.error as e:
            if (e.args[0] == errno.ECONNRESET and
                    (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
                # freebsd and Mach don't follow POSIX semantic of recv
                # and fail with ECONNRESET if peer performed shutdown.
                # See corresponding comment and code in TSocket::read()
                # in lib/cpp/src/transport/TSocket.cpp.
                self.close()
                # Trigger the check to raise the END_OF_FILE exception below.
                buff = ''
            else:
                raise
        if len(buff) == 0:
            raise TTransportException(type=TTransportException.END_OF_FILE,
                                      message='TSocket read 0 bytes')
        return buff

我认为它可能是由遇到errno.ECONNRESET错误引起的,当服务器故意关闭连接时,可能会发生这种错误。(根据这个node-js-econnreset,当服务器太忙并且发现连接超过“保持活动”超时时,服务器可能会终止连接)

您可以检查您的服务器日志,并发现是否存在某种终止连接行为。在

我不确定,只是提供我的想法。在

相关问题 更多 >