1

我已经搜索和搜索,但找不到答案。我正在尝试在两个 unix 设备之间打开一个 Pyro 连接。我可以使用具有相同 URI 字符串的 Pyro4 代理连接到设备 4 次。在第五个连接上,实例挂起我的获取数据函数调用。它通过 core.py pyro 包并最终等待获取数据。偶尔,在第四个之后创建的这些打开的连接之一会抛出一个 ConnectionClosedError 异常,如下所示:

 ConnectionClosedError("receiving: connection lost: "+str(x))
 ConnectionClosedError: receiving: connection lost: [Errno 104] Connection reset by peer

如果我不清楚,以下是导致此问题的原因: - 在与设备的不同 SSH 会话上打开 4 个连接,并运行设置 pyro 代理的重复测试。(这些工作正常且完整,没有错误)-打开更多连接,所有连接都挂在我的电话上以获取数据。它们挂起至少 5 分钟,有些会不经常引发上述异常。-并非所有人都会这样做。一旦 4 个正在运行的测试中的 1 个完成,挂起的第 5 个测试将启动并正常完成。其他人将跟随,但一次不会超过 4 个。

最后,以下代码(在 socketutil.py 中)是实际发生异常的地方:

def receiveData(sock, size):
    """Retrieve a given number of bytes from a socket.
    It is expected the socket is able to supply that number of bytes.
    If it isn't, an exception is raised (you will not get a zero length result
    or a result that is smaller than what you asked for). The partial data that
    has been received however is stored in the 'partialData' attribute of
    the exception object."""
    try:
        retrydelay=0.0
        msglen=0
        chunks=[]
        if hasattr(socket, "MSG_WAITALL"):
            # waitall is very convenient and if a socket error occurs,
            # we can assume the receive has failed. No need for a loop,
            # unless it is a retryable error.
            # Some systems have an erratic MSG_WAITALL and sometimes still return
            # less bytes than asked. In that case, we drop down into the normal
            # receive loop to finish the task.
           while True:
            try:
                data=sock.recv(size, socket.MSG_WAITALL)
                if len(data)==size:
                    return data
                # less data than asked, drop down into normal receive loop to finish
                msglen=len(data)
                chunks=[data]
                break
            except socket.timeout:
                raise TimeoutError("receiving: timeout")
            except socket.error:
                x=sys.exc_info()[1]
                err=getattr(x, "errno", x.args[0])
                if err not in ERRNO_RETRIES:
                    ################HERE:###############
                    raise ConnectionClosedError("receiving: connection lost: "+str(x))
                time.sleep(0.00001+retrydelay)  # a slight delay to wait before retrying
                retrydelay=__nextRetrydelay(retrydelay)

真的很感激这里的一些方向。提前致谢!

4

1 回答 1

0

原来这是服务器在启动时创建的最小线程数。出于某种原因,它不会在应该添加的时候再添加。

于 2013-03-14T03:32:14.437 回答