def gevent_wait_callback(conn, timeout=None):
 while 1:
  state = conn.poll()
  if (state == extensions.POLL_OK):
   break
  elif (state == extensions.POLL_READ):
   wait_read(conn.fileno(), timeout=timeout)
  elif (state == extensions.POLL_WRITE):
   wait_write(conn.fileno(), timeout=timeout)
  else:
   raise psycopg2.OperationalError(('Bad result from poll: %r' % state))

def gevent_wait_callback ( conn , timeout = None ) : while 1 : state = conn . poll ( ) if ( state == extensions . POLL_OK ) : break elif ( state == extensions . POLL_READ ) : wait_read ( conn . fileno ( ) , timeout = timeout ) elif ( state == extensions . POLL_WRITE ) : wait_write ( conn . fileno ( ) , timeout = timeout ) else : raise psycopg2 . OperationalError ( ( 'Bad result from poll: %r' % state ) )
a wait callback useful to allow gevent to work with psycopg .