Issue #21149: Improved thread-safety in logging cleanup during interpreter shutdown.
Closes #21149: Improved thread-safety in logging cleanup during interpreter shutdown.