Skip to content

Commit

Permalink
fix for "too many clients" with galaxy tools
Browse files Browse the repository at this point in the history
  • Loading branch information
abretaud committed Aug 20, 2019
1 parent 1362bd0 commit 5739201
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions chado/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy.pool import NullPool

standard_library.install_aliases()

Expand All @@ -34,7 +35,8 @@ class ChadoModel(object):

class ChadoInstance(object):

def __init__(self, dbhost="localhost", dbname="chado", dbuser="chado", dbpass="chado", dbschema="public", dbport=5432, dburl=None, offline=False, no_reflect=False, reflect_tripal_tables=False, **kwargs):
def __init__(self, dbhost="localhost", dbname="chado", dbuser="chado", dbpass="chado", dbschema="public", dbport=5432, dburl=None, offline=False,
no_reflect=False, reflect_tripal_tables=False, pool_connections=True, **kwargs):
self.dbhost = dbhost
self.dbname = dbname
self.dbuser = dbuser
Expand All @@ -47,9 +49,17 @@ def __init__(self, dbhost="localhost", dbname="chado", dbuser="chado", dbpass="c
if '@[' in self.dburl:
# the url given by pglite is not in the correct format for sqlalchmemy
self.dburl = re.sub(r"postgres://(.+)@\[(.+)\]/(.+)", r"postgres://\1@/\3?host=\2", self.dburl)
self._engine = create_engine('%s' % (self.dburl))
engine_url = self.dburl
else:
self._engine = create_engine('postgresql://%s:%s@%s:%s/%s' % (self.dbuser, self.dbpass, self.dbhost, self.dbport, self.dbname))
engine_url = 'postgresql://%s:%s@%s:%s/%s' % (self.dbuser, self.dbpass, self.dbhost, self.dbport, self.dbname)

if pool_connections:
self._engine = create_engine(engine_url)
else:
# Prevent SQLAlchemy to make a connection pool.
# Useful for galaxy dynamic options as otherwise it triggers "sorry, too many clients already" errors after a while
self._engine = create_engine(engine_url, poolclass=NullPool)

self._metadata = MetaData(self._engine, schema=self.dbschema)
Session = sessionmaker(bind=self._engine)
self.session = Session()
Expand Down

0 comments on commit 5739201

Please sign in to comment.