I am facing one issue where psycopg2 conn.poll() hangs when used with sshtunnel.
Actual issue is when you create sshtunnel to connect to the PostgreSQL database
server and executes any wrong query application got hangs on conn.poll() call.

I have created this sample application where I have used sshtunnel v0.1.4 and
psycopg2 v2.7.5. Before running this application please perform below steps:

  1) Create one directory "mkdir venv"
  2) go to that directory "cd venv"
  3) Create new virtual environment by running "virtualenv -p <path of the python> ."
     For example "virtualenv -p /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 ."
  4) Activate the virtual environment by running "source bin/activate"
  5) Run "pip install -r "<path>/Hang_Sample_Application/requirements.txt"
  6) Open config.py present in "Hang_Sample_Application" folder and provide the required information
     to connect to the database. Specifically DATABASE_SERVER_PASSWORD, SSH_TUNNEL_USERNAME,
     and SSH_TUNNEL_PASSWORD.
  7) If database server is on remote machine than check the entry in the pg_hba.conf file.
  8) Run "python <path>/Hang_Sample_Application/hang_ssh_tunnel.py"

Output: Some times you will get the message "Successfully executed the WRONG query."
        and sometimes application hangs in poll() function of psycopg2. In case if
        wrong query also gets executed successfully please try multiple times. Please
        refer the “Hang_Screenshot” file present in "Hang_Sample_Application" folder.  
