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.1k 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 10 Jul 2023, 19:28 last edited by bebewinla 7 Oct 2023, 19:35
    #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]

    S 1 Reply Last reply 10 Jul 2023, 19:38
    0
    • B bebewinla
      10 Jul 2023, 19:28

      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]

      S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Jul 2023, 19:38 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 10 Jul 2023, 19:41
      0
      • S SGaist
        10 Jul 2023, 19:38

        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 10 Jul 2023, 19:41 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.

        S 1 Reply Last reply 10 Jul 2023, 19:43
        0
        • B bebewinla
          10 Jul 2023, 19:41

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

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Jul 2023, 19:43 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 10 Jul 2023, 19:52
          0
          • S SGaist moved this topic from Qt 6 on 10 Jul 2023, 19:43
          • S SGaist
            10 Jul 2023, 19:43

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

            B Offline
            B Offline
            bebewinla
            wrote on 10 Jul 2023, 19:52 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.

            J 1 Reply Last reply 11 Jul 2023, 05:50
            0
            • B bebewinla
              10 Jul 2023, 19:52

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

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 11 Jul 2023, 05:50 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

              1/6

              10 Jul 2023, 19:28

              • Login

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