Skip to content

Commit

Permalink
add option to pass existing MongoClient instance to MongoObserver
Browse files Browse the repository at this point in the history
The point of this is to allow one to avoid creating redundant instances of MongoClient
  • Loading branch information
rueberger committed Apr 13, 2018
1 parent 5bbdf20 commit 38bbb7f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sacred/observers/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ class MongoObserver(RunObserver):

@staticmethod
def create(url='localhost', db_name='sacred', collection='runs',
overwrite=None, priority=DEFAULT_MONGO_PRIORITY, **kwargs):
overwrite=None, priority=DEFAULT_MONGO_PRIORITY,
client=None,**kwargs):
import pymongo
import gridfs
client = pymongo.MongoClient(url, **kwargs)

if client is not None:
assert isinstance(client, pymongo.MongoClient)
else:
client = pymongo.MongoClient(url, **kwargs)
database = client[db_name]
if collection in MongoObserver.COLLECTION_NAME_BLACKLIST:
raise KeyError('Collection name "{}" is reserved. '
Expand Down

0 comments on commit 38bbb7f

Please sign in to comment.