Log unhandled exceptions stacktraces in log files
This commit is contained in:
parent
2f5f260c18
commit
ecb0a1f79f
@ -18,6 +18,8 @@ Upcoming Release
|
||||
|
||||
* Add warning when BEV availability weekly profile has negative values in `build_transport_demand`.
|
||||
|
||||
* Stacktrace of uncaught exceptions should now be correctly included inside log files (via `configure_logging(..)`).
|
||||
|
||||
|
||||
PyPSA-Eur 0.9.0 (5th January 2024)
|
||||
==================================
|
||||
|
@ -80,6 +80,7 @@ def configure_logging(snakemake, skip_handlers=False):
|
||||
Do (not) skip the default handlers created for redirecting output to STDERR and file.
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
|
||||
kwargs = snakemake.config.get("logging", dict()).copy()
|
||||
kwargs.setdefault("level", "INFO")
|
||||
@ -103,6 +104,14 @@ def configure_logging(snakemake, skip_handlers=False):
|
||||
)
|
||||
logging.basicConfig(**kwargs)
|
||||
|
||||
# Setup a function to handle uncaught exceptions and include them with their stacktrace into logfiles
|
||||
def handle_exception(exc_type, exc_value, exc_traceback):
|
||||
# Log the exception
|
||||
logger = logging.getLogger()
|
||||
logger.error("Uncaught exception",
|
||||
exc_info=(exc_type, exc_value, exc_traceback))
|
||||
|
||||
sys.excepthook = handle_exception
|
||||
|
||||
def update_p_nom_max(n):
|
||||
# if extendable carriers (solar/onwind/...) have capacity >= 0,
|
||||
|
Loading…
Reference in New Issue
Block a user