From 79cbc8586ad4fc80aa45c7a8ecdc1fb8667df2c1 Mon Sep 17 00:00:00 2001 From: John Hennig Date: Sat, 16 Oct 2021 22:13:18 +0200 Subject: [PATCH] Only deactivate fault handler when exiting on Windows. Tests have shown that this has no effect on Linux. With our without this, the `InterruptedExcetion` discussed in #38 still occurs at exit about the same number of times. So it's best not to touch this. --- mph/session.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mph/session.py b/mph/session.py index 0660d81..9cb3a04 100755 --- a/mph/session.py +++ b/mph/session.py @@ -155,9 +155,21 @@ def cleanup(): log.exception(error) if jpype.isJVMStarted(): log.info('Exiting the Java virtual machine.') + # Work around Unix-style "lazy writing" before we pull the plug. sys.stdout.flush() sys.stderr.flush() - faulthandler.disable() + # Only deactivate fault handler on Windows, just like we do in + # `Client.__init__()`. pyTest seems to turn them back on right + # before entering the exit sequence. On Linux, we do get the + # occasional segmentation fault when running tests, just as + # pyTest exits. But disabling the fault handler doesn't help, + # so let's not touch it. It does seem to have some effect on + # Windows, but even there the benefit is fairly unclear. + if platform.system() == 'Windows' and faulthandler.is_enabled(): + log.debug('Turning off Python fault handlers.') + faulthandler.disable() + # Exit the hard way as Comsol leaves us no choice. See issue #38. jpype.java.lang.Runtime.getRuntime().exit(exit_code) - # No code is reached from here on due to the hard exit of the JVM. - log.info('Java virtual machine has exited.') + # No Python code is reached from here on. + # We would like to log that the Java VM has exited, but we can't. + # log.info('Java virtual machine has exited.')