Skip to content

Commit

Permalink
Merge pull request #146 from commonsense/local-socket
Browse files Browse the repository at this point in the history
Use a local socket connection to the ConceptNet database
  • Loading branch information
Rob Speer authored Jan 31, 2018
2 parents 00b2f1d + 52cd137 commit 709d757
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions conceptnet5/db/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os

DB_USERNAME = os.environ.get('CONCEPTNET_DB_USER', os.environ.get('USER', 'postgres'))
DB_PASSWORD = os.environ.get('CONCEPTNET_DB_PASSWORD', '')
DB_HOSTNAME = os.environ.get('CONCEPTNET_DB_HOSTNAME', 'localhost')
DB_PORT = int(os.environ.get('CONCEPTNET_DB_PORT', '5432'))
DB_NAME = os.environ.get('CONCEPTNET_DB_NAME', 'conceptnet5')
DB_PASSWORD = os.environ.get('CONCEPTNET_DB_PASSWORD')
DB_SOCKET = '/var/run/postgresql/.s.PGSQL.5432'

11 changes: 4 additions & 7 deletions conceptnet5/db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ def get_db_connection(dbname=None, building=False):
except pg8000.InterfaceError:
if attempt == 0:
print(
"Database %r at %s:%s is not available, retrying for 10 seconds"
% (dbname, config.DB_HOSTNAME, config.DB_PORT),
"Database %r is not available, retrying for 10 seconds" % dbname,
file=sys.stderr
)
time.sleep(1)
raise IOError(
"Couldn't connect to database %r at %s:%s" %
(dbname, config.DB_HOSTNAME, config.DB_PORT)
"Couldn't connect to database %r" % dbname
)


def _get_db_connection_inner(dbname):
conn = pg8000.connect(
user=config.DB_USERNAME,
password=config.DB_PASSWORD,
host=config.DB_HOSTNAME,
port=config.DB_PORT,
password=config.DB_PASSWORD or None,
unix_sock=config.DB_SOCKET,
database=dbname
)
pg8000.paramstyle = 'named'
Expand Down

0 comments on commit 709d757

Please sign in to comment.