psycopg2.pool.Simpleconnectionpool, Operationalerror exception takes time to launch

Asked

Viewed 105 times

0

I ran a test, shut down the server and called the method psycopg2.pool.SimpleConnectionPool, the method is waiting for a response for a very long time, about a minute, only then it raises the exception OperationalError. Is that normal? Is there any way to decrease this waiting time?

>>>import psycopg2, psycopg2.pool
>>> a=psycopg2.pool.SimpleConnectionPool(1, 2, host = 'ip-do-server', user = 'postgres', password = 'postgres', database = 'nomebanco', port = 5432)
  • Post the code responsible for this routine, so it’s better for the community to help you, I also suggest you do a tour to learn more about the site.

  • The code is simple: >>>import psycopg2, psycopg2.pool >>> a=psycopg2.pool.Simpleconnectionpool(1, 2, host = 'ip-do-server', user = 'postgres', password = 'postgres', database = 'basename', port = 5432) . . . Only after almost a minute does the exception come: psycopg2.Operationalerror: could not connect to server: Connection timed out Is the server running on host "192.168.56.2" and Accepting TCP/IP Connections on port 5432?

  • 1

    Click the 'edit' button and add the code to the question.

  • Follow on ubuntupaste http://paste.ubuntu.com/14597266/

1 answer

0


Use the parameter connect_timeout in seconds:

psycopg2.pool.SimpleConnectionPool (
    1, 2,
    host = 'ip-do-server',
    user = 'postgres',
    password = 'postgres',
    database = 'nomebanco',
    port = 5432,
    connect_timeout = 15
)

The parameters of class SimpleConnectionPool are passed to the function connect:

New minconn Connections are created Automatically. The pool will support a Maximum of about maxconn Connections. *args and **kwargs are passed to the connect() Function.

Which in turn refers to libpq:

The Connection Parameters can be specified either as a libpq Connection string using the dsn Parameter or using a set of keyword Arguments

  • Ummmmmm. I didn’t know about this parameter. The documentation does not measure, it only cites the nomenclature class psycopg2.pool.Simpleconnectionpool(minconn, maxconn, *args, **kwargs) If the documentation does not mention how do I know what the parameters are? I saw that you linked the libpq doc. I think the psycopg doc should mention these parameters, otherwise it gets a little complicated, consult in the libpq doc what should be psycopg2 doc

  • @Matheus: See the response update.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.