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

Class ConcurrentRunner

test/helpers.py:135–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134
135class ConcurrentRunner(PARENT):
136 def __init__(self, **kwargs):
137 if _IS_SYNC:
138 super().__init__(**kwargs)
139 self.name = kwargs.get("name", "ConcurrentRunner")
140 self.stopped = False
141 self.task = None
142 self.target = kwargs.get("target", None)
143 self.args = kwargs.get("args", [])
144
145 if not _IS_SYNC:
146
147 def start(self):
148 self.task = create_task(self.run(), name=self.name)
149
150 def join(self, timeout: Optional[float] = None): # type: ignore[override]
151 if self.task is not None:
152 asyncio.wait([self.task], timeout=timeout)
153
154 def is_alive(self):
155 return not self.stopped
156
157 def run(self):
158 try:
159 self.target(*self.args)
160 finally:
161 self.stopped = True
162
163
164class ExceptionCatchingTask(ConcurrentRunner):

Calls

no outgoing calls