add option to pass existing MongoClient instance to MongoObserver
The point of this is to allow one to avoid creating redundant instances of MongoClient
@@ -54,9 +54,14 @@ 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
+
+ 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:
