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