def _wait_select(conn):
 while 1:
  try:
   state = conn.poll()
   if (state == POLL_OK):
    break
   elif (state == POLL_READ):
    select.select([conn.fileno()], [], [], _WAIT_SELECT_TIMEOUT)
   elif (state == POLL_WRITE):
    select.select([], [conn.fileno()], [], _WAIT_SELECT_TIMEOUT)
   else:
    raise conn.OperationalError(('bad state from poll: %s' % state))
  except KeyboardInterrupt:
   conn.cancel()
   continue

def _wait_select ( conn ) : while 1 : try : state = conn . poll ( ) if ( state == POLL_OK ) : break elif ( state == POLL_READ ) : select . select ( [ conn . fileno ( ) ] , [ ] , [ ] , _WAIT_SELECT_TIMEOUT ) elif ( state == POLL_WRITE ) : select . select ( [ ] , [ conn . fileno ( ) ] , [ ] , _WAIT_SELECT_TIMEOUT ) else : raise conn . OperationalError ( ( 'bad state from poll: %s' % state ) ) except KeyboardInterrupt : conn . cancel ( ) continue
copy-pasted from psycopg2 .