<bdo id='YYCb6'></bdo><ul id='YYCb6'></ul>
  • <tfoot id='YYCb6'></tfoot>

    1. <small id='YYCb6'></small><noframes id='YYCb6'>

    2. <legend id='YYCb6'><style id='YYCb6'><dir id='YYCb6'><q id='YYCb6'></q></dir></style></legend>

      1. <i id='YYCb6'><tr id='YYCb6'><dt id='YYCb6'><q id='YYCb6'><span id='YYCb6'><b id='YYCb6'><form id='YYCb6'><ins id='YYCb6'></ins><ul id='YYCb6'></ul><sub id='YYCb6'></sub></form><legend id='YYCb6'></legend><bdo id='YYCb6'><pre id='YYCb6'><center id='YYCb6'></center></pre></bdo></b><th id='YYCb6'></th></span></q></dt></tr></i><div id='YYCb6'><tfoot id='YYCb6'></tfoot><dl id='YYCb6'><fieldset id='YYCb6'></fieldset></dl></div>

        确保 psycopg2 数据库连接处于活动状态

        Making sure that psycopg2 database connection alive(确保 psycopg2 数据库连接处于活动状态)

            <tbody id='FrsCI'></tbody>
          <i id='FrsCI'><tr id='FrsCI'><dt id='FrsCI'><q id='FrsCI'><span id='FrsCI'><b id='FrsCI'><form id='FrsCI'><ins id='FrsCI'></ins><ul id='FrsCI'></ul><sub id='FrsCI'></sub></form><legend id='FrsCI'></legend><bdo id='FrsCI'><pre id='FrsCI'><center id='FrsCI'></center></pre></bdo></b><th id='FrsCI'></th></span></q></dt></tr></i><div id='FrsCI'><tfoot id='FrsCI'></tfoot><dl id='FrsCI'><fieldset id='FrsCI'></fieldset></dl></div>

          1. <tfoot id='FrsCI'></tfoot>
            • <bdo id='FrsCI'></bdo><ul id='FrsCI'></ul>
              <legend id='FrsCI'><style id='FrsCI'><dir id='FrsCI'><q id='FrsCI'></q></dir></style></legend>
              • <small id='FrsCI'></small><noframes id='FrsCI'>

                  本文介绍了确保 psycopg2 数据库连接处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 python 应用程序,它打开一个可以在线挂起一个小时的数据库连接,但有时数据库服务器会重新启动,虽然 python 仍然有连接,但它不会与 OperationalError 异常一起工作.

                  I have a python application that opens a database connection that can hang online for an hours, but sometimes the database server reboots and while python still have the connection it won't work with OperationalError exception.

                  所以我正在寻找任何可靠的方法来ping"数据库并知道连接是活动的.我检查了 psycopg2 文档,但找不到类似的东西.当然,我可以发出一些简单的 SQL 语句,例如 SELECT 1 并捕获异常,但我希望有一个本地方法,例如 PHP pg_connection_status

                  So I'm looking for any reliable method to "ping" the database and know that connection is alive. I've checked a psycopg2 documentation but can't find anything like that. Sure I can issue some simple SQL statement like SELECT 1 and catch the exception, but I hope there is a native method, something like PHP pg_connection_status

                  谢谢.

                  推荐答案

                  pg_connection_status是使用PQstatus实现的.psycopg 不公开该 API,因此检查不可用.psycopg 调用 PQstatus 本身的唯一两个地方是建立新连接时和开始执行时.所以是的,您需要发出一个简单的 SQL 语句来确定连接是否仍然存在.

                  pg_connection_status is implemented using PQstatus. psycopg doesn't expose that API, so the check is not available. The only two places psycopg calls PQstatus itself is when a new connection is made, and at the beginning of execute. So yes, you will need to issue a simple SQL statement to find out whether the connection is still there.

                  这篇关于确保 psycopg2 数据库连接处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                        <bdo id='0pBfW'></bdo><ul id='0pBfW'></ul>
                          <tbody id='0pBfW'></tbody>
                      • <legend id='0pBfW'><style id='0pBfW'><dir id='0pBfW'><q id='0pBfW'></q></dir></style></legend>

                          <tfoot id='0pBfW'></tfoot>

                            <small id='0pBfW'></small><noframes id='0pBfW'>

                            <i id='0pBfW'><tr id='0pBfW'><dt id='0pBfW'><q id='0pBfW'><span id='0pBfW'><b id='0pBfW'><form id='0pBfW'><ins id='0pBfW'></ins><ul id='0pBfW'></ul><sub id='0pBfW'></sub></form><legend id='0pBfW'></legend><bdo id='0pBfW'><pre id='0pBfW'><center id='0pBfW'></center></pre></bdo></b><th id='0pBfW'></th></span></q></dt></tr></i><div id='0pBfW'><tfoot id='0pBfW'></tfoot><dl id='0pBfW'><fieldset id='0pBfW'></fieldset></dl></div>