Helper class to remove a dummy thread from threading._active on __del__.
| 1407 | |
| 1408 | |
| 1409 | class _DeleteDummyThreadOnDel: |
| 1410 | ''' |
| 1411 | Helper class to remove a dummy thread from threading._active on __del__. |
| 1412 | ''' |
| 1413 | |
| 1414 | def __init__(self, dummy_thread): |
| 1415 | self._dummy_thread = dummy_thread |
| 1416 | self._tident = dummy_thread.ident |
| 1417 | # Put the thread on a thread local variable so that when |
| 1418 | # the related thread finishes this instance is collected. |
| 1419 | # |
| 1420 | # Note: no other references to this instance may be created. |
| 1421 | # If any client code creates a reference to this instance, |
| 1422 | # the related _DummyThread will be kept forever! |
| 1423 | _thread_local_info._track_dummy_thread_ref = self |
| 1424 | |
| 1425 | def __del__(self, _active_limbo_lock=_active_limbo_lock, _active=_active): |
| 1426 | with _active_limbo_lock: |
| 1427 | if _active.get(self._tident) is self._dummy_thread: |
| 1428 | _active.pop(self._tident, None) |
| 1429 | |
| 1430 | |
| 1431 | # Dummy thread class to represent threads not started here. |