(self)
| 242 | raise errors[0] |
| 243 | |
| 244 | def test_join_then_self_join(self): |
| 245 | # make sure we can't deadlock in the following scenario with |
| 246 | # threads t0 and t1 (see comment in `ThreadHandle_join()` for more |
| 247 | # details): |
| 248 | # |
| 249 | # - t0 joins t1 |
| 250 | # - t1 self joins |
| 251 | def make_lock(): |
| 252 | lock = thread.allocate_lock() |
| 253 | lock.acquire() |
| 254 | return lock |
| 255 | |
| 256 | error = None |
| 257 | self_joiner_handle = None |
| 258 | self_joiner_started = make_lock() |
| 259 | self_joiner_barrier = make_lock() |
| 260 | def self_joiner(): |
| 261 | nonlocal error |
| 262 | |
| 263 | self_joiner_started.release() |
| 264 | self_joiner_barrier.acquire() |
| 265 | |
| 266 | try: |
| 267 | self_joiner_handle.join() |
| 268 | except Exception as e: |
| 269 | error = e |
| 270 | |
| 271 | joiner_started = make_lock() |
| 272 | def joiner(): |
| 273 | joiner_started.release() |
| 274 | self_joiner_handle.join() |
| 275 | |
| 276 | with threading_helper.wait_threads_exit(): |
| 277 | self_joiner_handle = thread.start_joinable_thread(self_joiner) |
| 278 | # Wait for the self-joining thread to start |
| 279 | self_joiner_started.acquire() |
| 280 | |
| 281 | # Start the thread that joins the self-joiner |
| 282 | joiner_handle = thread.start_joinable_thread(joiner) |
| 283 | |
| 284 | # Wait for the joiner to start |
| 285 | joiner_started.acquire() |
| 286 | |
| 287 | # Not great, but I don't think there's a deterministic way to make |
| 288 | # sure that the self-joining thread has been joined. |
| 289 | time.sleep(0.1) |
| 290 | |
| 291 | # Unblock the self-joiner |
| 292 | self_joiner_barrier.release() |
| 293 | |
| 294 | self_joiner_handle.join() |
| 295 | joiner_handle.join() |
| 296 | |
| 297 | with self.assertRaisesRegex(RuntimeError, "Cannot join current thread"): |
| 298 | raise error |
| 299 | |
| 300 | def test_join_with_timeout(self): |
| 301 | lock = thread.allocate_lock() |
nothing calls this directly
no test coverage detected