MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / _run

Method _run

pymongo/periodic_executor.py:96–120  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

94 self._skip_sleep = True
95
96 async def _run(self) -> None:
97 # The CSOT contextvars must be cleared inside the executor task before execution begins
98 _csot.reset_all()
99 while not self._stopped:
100 if self._task and self._task.cancelling(): # type: ignore[unused-ignore, attr-defined]
101 raise asyncio.CancelledError
102 try:
103 if not await self._target():
104 self._stopped = True
105 break
106 # Catch KeyboardInterrupt, CancelledError, etc. and cleanup.
107 except BaseException:
108 self._stopped = True
109 raise
110
111 if self._skip_sleep:
112 self._skip_sleep = False
113 else:
114 deadline = time.monotonic() + self._interval
115 while not self._stopped and time.monotonic() < deadline:
116 await asyncio.sleep(self._min_interval)
117 if self._event:
118 break # Early wake.
119
120 self._event = False
121
122
123class PeriodicExecutor:

Callers 1

openMethod · 0.95

Calls 2

cancellingMethod · 0.80
_targetMethod · 0.45

Tested by

no test coverage detected