MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / client_knobs

Class client_knobs

test/helpers.py:42–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41
42class client_knobs:
43 def __init__(
44 self,
45 heartbeat_frequency=None,
46 min_heartbeat_interval=None,
47 kill_cursor_frequency=None,
48 events_queue_frequency=None,
49 ):
50 self.heartbeat_frequency = heartbeat_frequency
51 self.min_heartbeat_interval = min_heartbeat_interval
52 self.kill_cursor_frequency = kill_cursor_frequency
53 self.events_queue_frequency = events_queue_frequency
54
55 self.old_heartbeat_frequency = None
56 self.old_min_heartbeat_interval = None
57 self.old_kill_cursor_frequency = None
58 self.old_events_queue_frequency = None
59 self._enabled = False
60 self._stack = None
61
62 def enable(self):
63 self.old_heartbeat_frequency = common.HEARTBEAT_FREQUENCY
64 self.old_min_heartbeat_interval = common.MIN_HEARTBEAT_INTERVAL
65 self.old_kill_cursor_frequency = common.KILL_CURSOR_FREQUENCY
66 self.old_events_queue_frequency = common.EVENTS_QUEUE_FREQUENCY
67
68 if self.heartbeat_frequency is not None:
69 common.HEARTBEAT_FREQUENCY = self.heartbeat_frequency
70
71 if self.min_heartbeat_interval is not None:
72 common.MIN_HEARTBEAT_INTERVAL = self.min_heartbeat_interval
73
74 if self.kill_cursor_frequency is not None:
75 common.KILL_CURSOR_FREQUENCY = self.kill_cursor_frequency
76
77 if self.events_queue_frequency is not None:
78 common.EVENTS_QUEUE_FREQUENCY = self.events_queue_frequency
79 self._enabled = True
80 # Store the allocation traceback to catch non-disabled client_knobs.
81 self._stack = "".join(traceback.format_stack())
82
83 def __enter__(self):
84 self.enable()
85
86 @no_type_check
87 def disable(self):
88 common.HEARTBEAT_FREQUENCY = self.old_heartbeat_frequency
89 common.MIN_HEARTBEAT_INTERVAL = self.old_min_heartbeat_interval
90 common.KILL_CURSOR_FREQUENCY = self.old_kill_cursor_frequency
91 common.EVENTS_QUEUE_FREQUENCY = self.old_events_queue_frequency
92 self._enabled = False
93
94 def __exit__(self, exc_type, exc_val, exc_tb):
95 self.disable()
96
97 def __call__(self, func):
98 def make_wrapper(f):
99 @wraps(f)

Calls

no outgoing calls