1717import threading
1818
1919from bson .objectid import ObjectId
20- from pymongo import monitor , pool
20+ from pymongo import common , monitor , pool
2121from pymongo .common import LOCAL_THRESHOLD_MS , SERVER_SELECTION_TIMEOUT
22+ from pymongo .errors import ConfigurationError
2223from pymongo .topology_description import TOPOLOGY_TYPE
2324from pymongo .pool import PoolOptions
2425from pymongo .server_description import ServerDescription
@@ -33,11 +34,16 @@ def __init__(self,
3334 monitor_class = None ,
3435 condition_class = None ,
3536 local_threshold_ms = LOCAL_THRESHOLD_MS ,
36- server_selection_timeout = SERVER_SELECTION_TIMEOUT ):
37+ server_selection_timeout = SERVER_SELECTION_TIMEOUT ,
38+ heartbeat_frequency = common .HEARTBEAT_FREQUENCY ):
3739 """Represent MongoClient's configuration.
3840
3941 Take a list of (host, port) pairs and optional replica set name.
4042 """
43+ if heartbeat_frequency < common .MIN_HEARTBEAT_INTERVAL :
44+ raise ConfigurationError ("%s cannot be less than %.1f" % (
45+ 'heartbeatFrequencyMS' , common .MIN_HEARTBEAT_INTERVAL ))
46+
4147 self ._seeds = seeds or [('localhost' , 27017 )]
4248 self ._replica_set_name = replica_set_name
4349 self ._pool_class = pool_class or pool .Pool
@@ -46,6 +52,7 @@ def __init__(self,
4652 self ._condition_class = condition_class or threading .Condition
4753 self ._local_threshold_ms = local_threshold_ms
4854 self ._server_selection_timeout = server_selection_timeout
55+ self ._heartbeat_frequency = heartbeat_frequency
4956 self ._direct = (len (self ._seeds ) == 1 and not replica_set_name )
5057 self ._topology_id = ObjectId ()
5158
@@ -82,6 +89,10 @@ def local_threshold_ms(self):
8289 def server_selection_timeout (self ):
8390 return self ._server_selection_timeout
8491
92+ @property
93+ def heartbeat_frequency (self ):
94+ return self ._heartbeat_frequency
95+
8596 @property
8697 def direct (self ):
8798 """Connect directly to a single server, or use a set of servers?
0 commit comments