... I understand the point there for reload(), but don't know of other use cases (let alone common ones <wink>) for wanting to leave a module in sys.modules when its code fails. What are they? Maybe it would be better for PyImport_ExecCodeModuleEx to purge a broken module unconditionally, and change PyImport_ReloadModule to put it back?
Attached is a patch that takes that approach. Code feels simpler/cleaner, since it makes a special case out of reload() instead of a special case out of everything except reload(). Still haven't thought of a case other than reload() that wants special treatment. The whole test suite still passes; it still fixes all the spurious test failures I know about on Windows when running the suite with -r.
The internal _RemoveModule() is incidentally more careful in this version of the patch. The last patch's new _AddModuleEx() no longer exists.