Closed svnv closed 8 years ago
This issue should have been fixed in Momoko 2.2.0. Can you please try with the latest 2.2.1? If it still does not work, please provide more details about your environment - python version, psycopg2 version, Linux flavour and postgresql server version.
P.S. You code looks correct from the first glance. I suggest you double-check against official tutorials.
Hmm, here is an overview of my system, I run the application using a virtualenv in osx:
env/bin/python --version
Python 2.7.10
$ env/bin/pip freeze | grep 'Momoko\|psycopg2\|tornado'
Momoko==2.2.1
psycopg2==2.6.1
tornado==4.2.1
$ uname -a
Darwin snvBook.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
The database is on another host, and is the following version:
$ uname -a
Linux multiweb-vpc 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
...
SELECT version();
version
----------------------------------------------------------------------------------------------
PostgreSQL 9.3.6 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.7.2-5) 4.7.2, 64-bit
Ahh, It's mac... I don't have an access to mac. I've tried it on Linux.
Your code as it is reveals another bug, but if I add time.sleep(1)
in the loop it works OK.
Can you please try with time.sleep(1)
and if it still does not work, can you please check whether https://github.com/psycopg/psycopg2/issues/263 still happens on mac?
Also I've fixed #127. You are welcome to try with the latest master as well.
EDIT, I did this with the pre #127 verison.
Adding a time.sleep(1)
inside the while
loop does not change behaviour on my mac, i still get the psycopg2.ProgrammingError execute cannot be used while an asynchronous query is underway
after the initial psycopg2.OperationalError
error.
I also tested the script in a docker container on my machine, and was not able to reproduce the bug there.
Then I would guess it's something related to your mac. Can you verify that https://github.com/psycopg/psycopg2/issues/263 does not happen on mac?
I've tested on the Mac before and IIRC established that it's a psycopg issue - you don't get the right connection status from it...
Using the the python 2 docker image i got the following in my shell when I disconnected and then reconnected the machine to the network:
db returned: 1
db returned: 1
could not translate host name "hostname" to address: Name or service not known
No database connection available
No database connection available
db returned: 1
db returned: 1
Looks fine to me.
I'm not really sure if this is an error in my application, momoko or psycopg2, but I have an application that is unable recover the database connection to a remote host, if the machine running the application loses network connectivity.
The application:
If I disconnect my computer from the network while the application is running, the application will eventually throw this exception:
psycopg2.OperationalError
with messageSSL SYSCALL error: Network is down\n
.And after throwing the first exception, I start getting
psycopg2.ProgrammingError
exceptions with messageexecute cannot be used while an asynchronous query is underway
. The application will continue to throw these exceptions forever, even if I reconnect my computer to the network.Is this an error in my application, momoko or psycopg2? I googled a bit around I found this https://github.com/psycopg/psycopg2/issues/263 in the github page for psycopg2, but I'm not sure if is related to my problem.