MCPcopy Index your code
hub / github.com/RustPython/RustPython / catch_threading_exception

Class catch_threading_exception

Lib/test/support/threading_helper.py:161–215  ·  view source on GitHub ↗

Context manager catching threading.Thread exception using threading.excepthook. Attributes set when an exception is caught: * exc_type * exc_value * exc_traceback * thread See threading.excepthook() documentation for these attributes. These attributes are del

Source from the content-addressed store, hash-verified

159
160
161class catch_threading_exception:
162 """
163 Context manager catching threading.Thread exception using
164 threading.excepthook.
165
166 Attributes set when an exception is caught:
167
168 * exc_type
169 * exc_value
170 * exc_traceback
171 * thread
172
173 See threading.excepthook() documentation for these attributes.
174
175 These attributes are deleted at the context manager exit.
176
177 Usage:
178
179 with threading_helper.catch_threading_exception() as cm:
180 # code spawning a thread which raises an exception
181 ...
182
183 # check the thread exception, use cm attributes:
184 # exc_type, exc_value, exc_traceback, thread
185 ...
186
187 # exc_type, exc_value, exc_traceback, thread attributes of cm no longer
188 # exists at this point
189 # (to avoid reference cycles)
190 """
191
192 def __init__(self):
193 self.exc_type = None
194 self.exc_value = None
195 self.exc_traceback = None
196 self.thread = None
197 self._old_hook = None
198
199 def _hook(self, args):
200 self.exc_type = args.exc_type
201 self.exc_value = args.exc_value
202 self.exc_traceback = args.exc_traceback
203 self.thread = args.thread
204
205 def __enter__(self):
206 self._old_hook = threading.excepthook
207 threading.excepthook = self._hook
208 return self
209
210 def __exit__(self, *exc_info):
211 threading.excepthook = self._old_hook
212 del self.exc_type
213 del self.exc_value
214 del self.exc_traceback
215 del self.thread
216
217
218def _can_start_thread() -> bool:

Callers 1

run_concurrentlyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected