From 42e19d21692733f72af256d52812e5acfb3b6318 Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Fri, 9 Sep 2016 14:45:03 +0100 Subject: [PATCH] Fix error highlighting, broken in d6391c7e9b26e5e10bb3. Fixes #1676 --- web/pgadmin/utils/driver/psycopg2/__init__.py | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/web/pgadmin/utils/driver/psycopg2/__init__.py b/web/pgadmin/utils/driver/psycopg2/__init__.py index d4465ea4b..95aa95cab 100644 --- a/web/pgadmin/utils/driver/psycopg2/__init__.py +++ b/web/pgadmin/utils/driver/psycopg2/__init__.py @@ -1044,9 +1044,31 @@ Failed to reset the connection to the server due to following error: if state == psycopg2.extensions.POLL_OK: return self.ASYNC_OK elif state == psycopg2.extensions.POLL_WRITE: - return self.ASYNC_WRITE_TIMEOUT + # Wait for the given time and then check the return status + # If three empty lists are returned then the time-out is reached. + timeout_status = select.select([], [conn.fileno()], [], time) + if timeout_status == ([], [], []): + return self.ASYNC_WRITE_TIMEOUT + + # poll again to check the state if it is still POLL_WRITE + # then return ASYNC_WRITE_TIMEOUT else return ASYNC_OK. + state = conn.poll() + if state == psycopg2.extensions.POLL_WRITE: + return self.ASYNC_WRITE_TIMEOUT + return self.ASYNC_OK elif state == psycopg2.extensions.POLL_READ: - return self.ASYNC_READ_TIMEOUT + # Wait for the given time and then check the return status + # If three empty lists are returned then the time-out is reached. + timeout_status = select.select([conn.fileno()], [], [], time) + if timeout_status == ([], [], []): + return self.ASYNC_READ_TIMEOUT + + # poll again to check the state if it is still POLL_READ + # then return ASYNC_READ_TIMEOUT else return ASYNC_OK. + state = conn.poll() + if state == psycopg2.extensions.POLL_READ: + return self.ASYNC_READ_TIMEOUT + return self.ASYNC_OK else: raise psycopg2.OperationalError( "poll() returned %s from _wait_timeout function" % state