Skip to content

Commit b064605

Browse files
committed
Silence LAL SWIG stdio and matplotlib font-manager noise on import
LAL enables SWIG stdout/stderr redirection under IPython/Jupyter, which carries a performance penalty and prints a "Wswiglal-redir-stdio" warning. Disable it on import via LAL's own swig_redirect_standard_output_error(False); set PYCBC_LAL_SWIG_REDIRECT_STDIO to keep LAL's native behaviour. Also raise the matplotlib.font_manager logger to WARNING so its flood of DEBUG "findfont: ..." records (tens of thousands per figure) no longer swamps the output of pycbc tools run with --verbose.
1 parent f6eaed2 commit b064605

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

pycbc/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,20 @@
2929
# Filter annoying Cython warnings that serve no good purpose.
3030
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
3131
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
32+
33+
# Disable LAL's SWIG stdio redirection (and its "Wswiglal-redir-stdio" warning
34+
# under IPython) by default. Set PYCBC_LAL_SWIG_REDIRECT_STDIO to keep it.
35+
if not os.environ.get("PYCBC_LAL_SWIG_REDIRECT_STDIO"):
36+
try:
37+
import lal as _lal
38+
_lal.swig_redirect_standard_output_error(False)
39+
except ImportError:
40+
pass
41+
3242
import logging
43+
44+
# Silence font_manager's DEBUG "findfont: ..." spam under --verbose.
45+
logging.getLogger("matplotlib.font_manager").setLevel(logging.WARNING)
3346
import random
3447
import string
3548
import importlib.util

0 commit comments

Comments
 (0)