From a4372e6e9a3e0fdbb84bf1b9b175a9a2ece0a93e Mon Sep 17 00:00:00 2001 From: Jack Betteridge Date: Wed, 15 Nov 2023 14:14:35 +0000 Subject: [PATCH] More WIP --- .github/workflows/ci.yml | 2 +- pyop2/mpi.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f346ae29f..788186ac9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: PETSC_ARCH: default PETSC_CONFIGURE_OPTIONS: --with-debugging=1 --with-shared-libraries=1 --with-c2html=0 --with-fortran-bindings=0 RDMAV_FORK_SAFE: 1 - PYOP2_LOG_LEVEL: DEBUG + PYOP2_CI_TESTS: 1 timeout-minutes: 60 steps: diff --git a/pyop2/mpi.py b/pyop2/mpi.py index fc9af46c5..56becceef 100644 --- a/pyop2/mpi.py +++ b/pyop2/mpi.py @@ -74,7 +74,8 @@ _DUPED_COMM_DICT = {} # Flag to indicate whether we are in cleanup (at exit) PYOP2_FINALIZED = False - +# Flag for outputting information at the end of testing (do not abuse!) +_running_under_pytest = bool(os.environ.get('PYOP2_CI_TESTS')) class PyOP2CommError(ValueError): pass @@ -178,6 +179,7 @@ def delcomm_outer(comm, keyval, icomm): # This will raise errors at cleanup time as some objects are already # deleted, so we just skip # ~ if not PYOP2_FINALIZED: + debug = finalize_safe_debug() if keyval not in (innercomm_keyval, compilationcomm_keyval): raise PyOP2CommError("Unexpected keyval") @@ -484,15 +486,21 @@ def compilation_comm(comm): return comp_comm +def finalize_safe_debug(): + if PYOP2_FINALIZED: + if logger.level > DEBUG and not _running_under_pytest: + debug = lambda string: None + else: + debug = lambda string: print(string) + return debug + + @atexit.register def _free_comms(): """Free all outstanding communicators.""" global PYOP2_FINALIZED PYOP2_FINALIZED = True - if logger.level > DEBUG: - debug = lambda string: None - else: - debug = lambda string: print(string) + debug = finalize_safe_debug() debug("PyOP2 Finalizing") # Collect garbage as it may hold on to communicator references