[Python] RuntimeError in DolphinDB Python SDK: Connection closed when reusing ddb.session -...

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I’m using the DolphinDB Python SDK and encountering connection issues when working with

    class methods. Here’s a simplified version of my code:

    class DBHandler:
    def connect_ddb(self):
    conn = ddb.session()
    conn.connect("xxx") # Host/port details
    return conn

    def funcA(self):
    conn = self.connect_ddb()
    conn.run("some_query")


    # Usage
    handler = DBHandler()
    for _ in range(100):
    handler.funcA() # Works initially but fails after several iterations


    The error occurs after some time of frequent usage:

    RuntimeError: <Exception> in run: Couldn't send script/function to the remote host because the connection has been closed


    I’m wondering what might be causing this issue. Is it because the connection established by ddb.session times out after a certain period? Or could there be other reasons? How can I fix this problem to ensure that the connection remains stable and the run method can be executed without errors?

    My environment:

    • DolphinDB Python API version: 3.0.2.3
    • DolphinDB server version: 3.00.2.5
    • Python version: 3.9.2rc1

    Continue reading...

Compartilhe esta Página