Enable the -Xrs flag when starting the JVM to allow signals to be propagated
Enable the -Xrs flag when starting the JVM to allow signals to be propagated fully back to Python and on to other systems such as Qt.
Merge request reports
Activity
This was removed recently in !69 (comment 4313762) (but was limited to
JPype <1
). @isinkare has an example that demonstrates its use in newer JPype versions (please leave a comment here with the code to reproduce).added 1 commit
- 591828c7 - Enable the -Xrs flag when starting the JVM to allow signals to be propagated...
import sys import jpype from PyQt5.QtWidgets import QApplication, QToolButton import signal; signal.signal(signal.SIGINT, signal.SIG_DFL) app = QApplication(sys.argv) jpype.startJVM() btn = QToolButton() btn.show() sys.exit(app.exec_())
Ctrl+C here produces an output:
QObject::~QObject: Timers cannot be stopped from another thread
Replacing
jpype.startJVM()
withjpype.startJVM('-Xrs')
makes the warning disappear.This warning is particularly visible when using
QToolButton
, that reimplements QObject.timerEvent(). More info in ACCPY-760.Thanks Ivan. Can you also check what the
interrupt
kwarg does with/without the-Xrs
flag (https://jpype.readthedocs.io/en/latest/api.html#jpype.startJVM)From what I understand,
interrupt
keyword is enabled by default when running a python file, and is disabled in interactive shell. This results in Ctrl+C terminating the process when running from file, and having no effect when running in interactive shell (presumably because application is still being in the Qt event loop, andSIGINT
handler is undone, or is not getting called). Generally, setting it explicitly toTrue
has no effect compared to omitting it, when running a Python file. One interesting thing, is that-Xrs
seems to override it, e.g.jpype.startJVM('-Xrs', interrupt=False)
will allow to still exit cleanly on Ctrl+C.
added 1 commit
- 0b3b2382 - Enable the -Xrs flag when starting the JVM to allow signals to be propagated...
enabled an automatic merge when the pipeline for 0b3b2382 succeeds
- Resolved by Philip Elson
Another example script, which doesn't involve Qt:
from time import sleep import signal from jpype import * startJVM( getDefaultJVMPath(), #'-Xrs', ) def handler(signum, frame): raise KeyboardInterrupt() #the overloaded signal handling has to be here to make KeyboardInterrupt work again #please comment out to check how the script dies without doing any clean-up #signal.signal(signal.SIGINT, handler) try: while True: print(".", end="", flush=True) sleep(1) except (BaseException, KeyboardInterrupt) as e: print(e, type(e)) finally: print("This should be always executed", flush=True)
mentioned in commit ff3a6b5c