@@ -70,10 +70,13 @@ class Arctic(object):
70
70
71
71
def __init__ (self , mongo_host , app_name = APPLICATION_NAME , allow_secondary = False ,
72
72
socketTimeoutMS = 10 * 60 * 1000 , connectTimeoutMS = 2 * 1000 ,
73
- serverSelectionTimeoutMS = 30 * 1000 ):
73
+ serverSelectionTimeoutMS = 30 * 1000 , ** kwargs ):
74
74
"""
75
75
Constructs a Arctic Datastore.
76
76
77
+ Note: If mongo_host is a pymongo connection and the process is later forked, the
78
+ new pymongo connection may have different parameters.
79
+
77
80
Parameters:
78
81
-----------
79
82
mongo_host: A MongoDB hostname, alias or Mongo Connection
@@ -92,6 +95,8 @@ def __init__(self, mongo_host, app_name=APPLICATION_NAME, allow_secondary=False,
92
95
the pymongo driver will spend on MongoDB cluster discovery. This parameter
93
96
takes precedence over connectTimeoutMS: https://jira.mongodb.org/browse/DRIVERS-222
94
97
98
+ kwargs: 'dict' extra keyword arguments to pass when calling pymongo.MongoClient,
99
+ for example ssl parameters.
95
100
"""
96
101
self ._application_name = app_name
97
102
self ._library_cache = {}
@@ -101,10 +106,13 @@ def __init__(self, mongo_host, app_name=APPLICATION_NAME, allow_secondary=False,
101
106
self ._server_selection_timeout = serverSelectionTimeoutMS
102
107
self ._lock = threading .RLock ()
103
108
self ._pid = os .getpid ()
109
+ self ._pymongo_kwargs = kwargs
104
110
105
111
if isinstance (mongo_host , string_types ):
112
+ self ._given_instance = False
106
113
self .mongo_host = mongo_host
107
114
else :
115
+ self ._given_instance = True
108
116
self .__conn = mongo_host
109
117
# Workaround for: https://jira.mongodb.org/browse/PYTHON-927
110
118
mongo_host .server_info ()
@@ -119,17 +127,21 @@ def _conn(self):
119
127
# http://api.mongodb.com/python/current/faq.html#using-pymongo-with-multiprocessing
120
128
curr_pid = os .getpid ()
121
129
if curr_pid != self ._pid :
130
+ if self ._given_instance :
131
+ logger .warn ("Forking process. Arctic was passed a pymongo connection during init, "
132
+ "the new pymongo connection may have different parameters." )
122
133
self ._pid = curr_pid # this line has to precede reset() otherwise we get to eternal recursion
123
134
self .reset () # also triggers re-auth
124
135
125
136
if self .__conn is None :
126
137
host = get_mongodb_uri (self .mongo_host )
127
138
logger .info ("Connecting to mongo: {0} ({1})" .format (self .mongo_host , host ))
128
139
self .__conn = pymongo .MongoClient (host = host ,
129
- maxPoolSize = self ._MAX_CONNS ,
130
- socketTimeoutMS = self ._socket_timeout ,
131
- connectTimeoutMS = self ._connect_timeout ,
132
- serverSelectionTimeoutMS = self ._server_selection_timeout )
140
+ maxPoolSize = self ._MAX_CONNS ,
141
+ socketTimeoutMS = self ._socket_timeout ,
142
+ connectTimeoutMS = self ._connect_timeout ,
143
+ serverSelectionTimeoutMS = self ._server_selection_timeout ,
144
+ ** self ._pymongo_kwargs )
133
145
self ._adminDB = self .__conn .admin
134
146
135
147
# Authenticate against admin for the user
0 commit comments