1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Mysql server has gone away and connection won't close

Discussão em 'Python' iniciado por Stack, Abril 1, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with Python, MySQL, and SQLAlchemy.

    I'm trying to debug company code that essentially pulls from an input database, references against a log database, and pushes to a Jira custom field. The input database is queried and a secondary table is created. From there, logic (updating, adding, disabling, enabled in order) is performed on the secondary table. The secondary table, log database, and Jira are all added and updated accordingly, but when it comes time to move on to disabling, I get the MySQL error 2006: mysql (input database) server has gone away, and disabling and enabling logic isn't completed. From how I understand it, the input database is queried and left sitting with an open connection.

    • I've tried creating a heartbeat that pings the input database every 5 minutes. This successfully prevented the error from happening, but the heartbeat continued even after the program had finished. This leads me to believe that the connection was still open even then.
    • I've tried forcing a close with session.close() immediately after the input database is queried and at the end of the program, but I found that it reopened later in the code even though that input database wasn't called again.
    • I've tried limiting parameters like pool_timeout, and seems like it had no effect.
    • All SQL settings (wait_timeouts, interactive_timeout, etc) are default. The whole program takes less than 30 minutes to run, so the default 8 hours is definitely more than enough.
    • I've found a work around that restarts the connection after the error throws. This results in the connection restarting, going back through adding and updating (0 rows), and focusing on disabling and enabling. But I would definitely prefer for no error to throw at all.

    Continue reading...

Compartilhe esta Página