Python script not exit
-
wrote on 10 Jul 2023, 19:28 last edited by bebewinla 7 Oct 2023, 19:35
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] -
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]Hi,
Since you are not showing any widgets, how are you stopping that script ?
Based on its content, there's no need for anything Qt in that script.
-
Hi,
Since you are not showing any widgets, how are you stopping that script ?
Based on its content, there's no need for anything Qt in that script.
-
I have widgets created after reading the text, but just to make it simple discard those. just testing the sys.ext(app.exe()) which is not working.
How are you calling and how are you trying to exit it ?
-
-
wrote on 10 Jul 2023, 19:52 last edited by
@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. -
@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...
1/6