Skip to content

fancylogger: catch broader exceptions when importing mpi4py#363

Open
WilleBell wants to merge 1 commit into
hpcugent:masterfrom
WilleBell:patch-1
Open

fancylogger: catch broader exceptions when importing mpi4py#363
WilleBell wants to merge 1 commit into
hpcugent:masterfrom
WilleBell:patch-1

Conversation

@WilleBell
Copy link
Copy Markdown

@WilleBell WilleBell commented Apr 3, 2026

In mixed Python environments, mpi4py import may raise exceptions other than ImportError (e.g. TypeError due to version mismatch). Broaden exception handling to avoid crashes and fall back gracefully.

To give some context: when using vsc-mympirun together with software bundles that include their own Python stack (e.g. OpenFOAM with ParaView), a conflicting mpi4py version may be picked up, leading to errors such as:

RuntimeWarning: compiletime version 3.12 of module 'mpi4py.MPI' does not match runtime version 3.9
TypeError: 'co_linetable' is an invalid keyword argument for replace()

Since fancylogger is a logging utility, it should not cause the application to fail in such situations. With this change, it falls back to non-MPI logging when mpi4py cannot be safely imported.

Note: this change only covers Python-level exceptions. In some mixed Python environments, importing mpi4py may still trigger a hard crash (e.g. due to ABI mismatches) before the exception handler is reached. Avoiding the mpi4py import entirely would be a more robust solution in such cases.

(see also #216)

In mixed Python environments, mpi4py import may raise exceptions other than ImportError (e.g. TypeError due to version mismatch). Broaden exception handling to avoid crashes and fall back gracefully.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant