Issue #9501: Improved shutdown handling to deal with module attributes correctly.