Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Python script not exit
Forum Updated to NodeBB v4.3 + New Features

Python script not exit

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bebewinla
    wrote on last edited by bebewinla
    #1

    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 file

    I 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, QMainWindow

    app = 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]

    SGaistS 1 Reply Last reply
    0
    • B bebewinla

      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 file

      I 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, QMainWindow

      app = 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]

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      0
      • SGaistS SGaist

        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.

        B Offline
        B Offline
        bebewinla
        wrote on last edited by
        #3

        @SGaist,

        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.

        SGaistS 1 Reply Last reply
        0
        • B bebewinla

          @SGaist,

          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.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How are you calling and how are you trying to exit it ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • SGaistS SGaist moved this topic from Qt 6 on
          • SGaistS SGaist

            How are you calling and how are you trying to exit it ?

            B Offline
            B Offline
            bebewinla
            wrote on last edited by
            #5

            @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.

            jsulmJ 1 Reply Last reply
            0
            • B bebewinla

              @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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @bebewinla

              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...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved