Skip to content

Commit

Permalink
Only deactivate fault handler when exiting on Windows.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
john-hen committed Oct 16, 2021
1 parent d6a3e8e commit 79cbc85
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions mph/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')

0 comments on commit 79cbc85

Please sign in to comment.