Python script not exit
-
I have this python script. The sys.exit(app.exec()) is not working
To run either :% ./my.py input
usage my.py [filename] [sourcefile]
or% ./my.py input notify.txt
text - This is notify txt fileI ran the script my.py either case, the script didn't exit. I couldn't understand why. I do not want to use "sys.exit()" since this is sort of nested with other script, if you sys.exit() then the process exits.
[code]
#!/usr/bin/python
import sys
from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QApplication, QMainWindowapp = QApplication(sys.argv)
main = QtWidgets.QMainWindow()
main.hide()
app.lastWindowClosed.connect(QApplication.quit)
if len(sys.argv) != 3:
print ("usage my.py [filename] [sourcefile]")
sys.exit(app.exec())
else:
text = ""
name = sys.argv[1]
fd = open(sys.argv[2])
text = fd.read()
print ("text - ", text)sys.exit(app.exec())
[/code] -
S SGaist moved this topic from Qt 6 on
-
@SGaist
I'm calling this my.py from a perl script "mytest".in mytest perl script, I have the following:
$cmd = "my.py filename textfile";
system($cmd);if the number of argv !=3, then it my.py should exit, but it doesn't.
If the argv is correct then output the textfile, then my.py should exit and return to the perl script. -
if len(sys.argv) != 3: print ("usage my.py [filename] [sourcefile]") sys.exit(app.exec())
If you want to exec this script here, then why are you starting Qt event loop calling app.exec()?! app.exec() is a blocking call and does NOT return until Qt event loop is terminated. There is absolutely no need to start Qt event loop if you want to exit the script...