omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    quit the script

    Pythonista
    8
    22
    24293
    Loading More Posts
    • 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.
    • jothirams117
      jothirams117 last edited by

      Hello,

      I have a script which I have saved as shortcut, to be executed from the homescreen (done using http://omz-software.com/pythonista/shortcut/)

      I would like my script to quit after it is done. How to do that. Currently it is showing the console output.

      1 Reply Last reply Reply Quote 0
      • filippocld223
        filippocld223 last edited by

        import sys
        sys.exit()

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          jothirams,

          I do not know of a supported way to shutdown the Pythonista app if that is what you are looking for.

          import sys; sys.exit() # terminates your script but does not shutdown the Pythonista app

          import console; console.clear() # Clears Pythonista's console output
          import console; console.hide_output() # Hide the console output area with a sliding animation.

          import webbrowser; webbrowser.open('http://python.org') # Switches to a website but Pythonista is still running
          You could use similar syntax to switch to another app that supports x-callback-url (see: http://x-callback-url.com) but Pythonista is still running in the background.

          Finally you could <b>crash the app</b> but this is always frowned upon and future Pythonista versions might fix the crashing behavior.

          <pre>import thread, time; thread.start_new_thread(time.sleep, (1,))</pre>

          UPDATE: The above code no longer crashes Pythonista as of v1.4.

          1 Reply Last reply Reply Quote 0
          • jothirams117
            jothirams117 last edited by

            @ccc - Yes, I was looking for an option to shutdown the app. For now I shall switch to my web browser, till Pythonista gives such an option.

            Thanks for clarifying in detail.

            1 Reply Last reply Reply Quote 0
            • omz
              omz last edited by

              There is no "clean" way to exit Pythonista programmatically. The crash @ccc mentioned will actually be fixed in the next update (though I'm sure there are other ways if you look hard enough). Normally, sys.exit() would do this, but I intentionally patched that away, because when you come from a Desktop OS, where an IDE typically doesn't run in the same process as the script you're executing (which is a technical necessity on iOS), this might not be the expected behavior, or worse, look like a crash.

              1 Reply Last reply Reply Quote 0
              • filippocld223
                filippocld223 last edited by

                @omz insert in console module
                console.exit()

                1 Reply Last reply Reply Quote 1
                • ccc
                  ccc last edited by ccc

                  One more crash the app script: import canvas; canvas.restore_gstate()

                  UPDATE: The above code no longer crashes Pythonista as of v1.4.

                  1 Reply Last reply Reply Quote 0
                  • technoway
                    technoway last edited by technoway

                    Is there still no function or method to shutdown Pythonista from within a script?

                    1 Reply Last reply Reply Quote 0
                    • ccc
                      ccc last edited by ccc

                      I believe that @omz post above is still correct. There is no supported way to auto-shutdown Pythonista because users would perceive it unexpected behavior for an iOS app. Do you know of other iOS apps that auto-shutdown?

                      Phuket2 technoway 2 Replies Last reply Reply Quote 0
                      • Phuket2
                        Phuket2 @ccc last edited by

                        @ccc , I think it still would be nice to be able to shutdown Pythonista via code. I understand why sys.exit() should not do it. But an implicit method to do it could be a good idea, hence no misunderstanding between the language vrs a platform feature.

                        1 Reply Last reply Reply Quote 0
                        • JonB
                          JonB last edited by

                          import os
                          os.abort()

                          1 Reply Last reply Reply Quote 0
                          • technoway
                            technoway last edited by technoway

                            JonB - Thanks for the reply. Unfortunately, os.abort() appears to do the same thing as os.exit(0). The app goes away, but the console window, and one other window, presumably the main Pythonista window, are running in the background and have to be closed separately.

                            I'm running the latest Pythonista beta on an iPhone 6s running IOS 11.2.1

                            I'm not complaining. Pythonista is great the way it is. That would be a nice feature though.

                            JonB 1 Reply Last reply Reply Quote 0
                            • technoway
                              technoway @ccc last edited by technoway

                              @ccc - I did some searching, and apparently Apple discourages calling exit(0) in objective C to close an app, because that appears similar to an app crashing.

                              My issue is that when I use a shortcut URL to launch my GUI application, when I hit the home button to close the app, there are two windows to close, not just one like most (all?) other apps.

                              Is there a way I can make my app so that it does not show the second window when I start the app this way?

                              I am using a uiView-derived window in my app.

                              cvp 1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @technoway last edited by cvp

                                @technoway Hi, when we start a script from an url, Pythonista shows the last edited file as first window, while the script is initialized.
                                I've put as last edited file, a .txt file with an ascii art content, that will say a drawing (I use Mona Lisa) done with ascii characters. This solution does not really solve the problem but it shows a "pretty" window of your choice as first window.

                                	      :';t)/!||||(//L+)'(-\\/ddjWWW#######WmKK(\!(/-|J=/\\t/!-/\!_L\) 
                                        |-!/(!-)\L\)/!\5(!.!LWW###################WK/|!\\\\/!;\/\T\/((\ 
                                        |!'//\//(-!t\Y/\L!m#####M####################WLt\\!)\/J-//)/;t\ 
                                        --/-.\.\/\.!)///m######K#######################WK!/!-( )-!,|/\ 
                                        //,\--`--!-/\(q#######DD##########################L\\\\-!!//!\\
                                        -.-!\'!!\-\/:W########N############################W,).'-.-/\-' 
                                        !.\!-!-!`!-!W#######P|+~**@@@#######################W/,/'\-/,\7 
                                        --`,-- -/.:W###*P!'          \`Z8#####################;,\\`,\,\
                                        `.'.'\`-.-d##5'-           -- '-:V@##########W#########_\-!-\\-
                                        `, -,.'/,G##K- '               - )7KM###################\-----/
                                        - '-  --:##@;                    -!ZZ###################W! \'!- 
                                         '-.`- G###|.                    `,D8K###################|/-.-/ 
                                        -' ,-//###@)                      -)ZWMW##################\` _\
                                        - ' .:Yd###!                     `-!(K5K##################|(/L|
                                          - :\G###Z-                    ` ! -;55ZZ#################)(4) 
                                         . -!W####!\                     `  ' !-tVG################XNVZ 
                                           tt####@-.                        `  ')(W################D)8@ 
                                           )8#####\                         .-`-/KW#################KD# 
                                          ||Z####W!-              .::,\.. -,;\bZKK######8#K#########(#8 
                                          KN8#####( ,:!/GG_      d4KW8ZKW#WWK#W#88#######W##########WK# 
                                         )/8K###K#W#WP~~~T4(    dW##7'___L#M####MM8W###W############bM8 
                                        \!48#K####8##W*###WY;   WRob+~~######*ff/\NM8###############WW# 
                                        .\\KW###W#,~t' !*~!',  -M@)    `~`,),' '.`K#################@KW 
                                        .'8M###### -'..j/Z''    @//-  ,,\\+\'    :|W######M###########8 
                                        :\#8#K###D              \!`             !:Z8###8@#####8W#W###8M 
                                        q8W5######             `!-             `-)8##################M8 
                                        8WZ8#M####-             /  .          .\tK############@######ZJ 
                                        #W#@K###W#|              //           \\tW@###@K##W##W###K###Wm 
                                        ##8#M#8###P-            -=/,         /;D8W##############@###W## 
                                        #8###M@####\-      ,   _)jJ;        -((WKK#####W####W##K######K 
                                        ###W@K##K##);     `\..KW##WK       )X)KW#M##W###MW##@#W######8# 
                                        #K#W####@#@@/;-     ~M####M\    ,.\\=)D8W##W###W##########8W##@ 
                                        ####MW######(`\\'     PPK((.:|/!-\-/)8XN@WMK#######W##MK#@##### 
                                        ##8##MK#W#@#b!--\)L_. .(ZLWbW#\'- ,-N|/KM#######W###@########W# 
                                        ##KW###K#W###/-  !``~~Yff*N5f -' -.\))KK#######MK##W###M8W#W### 
                                        #W###K@K######J--    .._dd/;)/- !//)NK#8W##########8########M#K 
                                        ##8W#K###W#####W!.   `YY\)\\)\7(-)4dW#8#@###K#W#######8######## 
                                        M####8##K#KW###W#/,       '-\\//)88W#M#@#K##M###@##M#8##@#W#8#M 
                                        ZW#W#M#K##########m       -)!/LtWW#W##@#W#####KW#######W###K### 
                                        K##W#####W#M#8#####KL   .-//dD##8W#K######8##########MK###W##M# 
                                        tN#W##W#W#M##########bb4dKW#@##W##K####MK####8###########W##### 
                                        )NM#8W##@###@##############@##@##8##K#W####M##K##K#@###8##M#### 
                                        (tMM###W##M8####@####@###@#########@####8W##8W################M 
                                        tNZ##K###W####@#####8###/4N##8#W##W##M#8#MK#M8#K######W######## 
                                        M/K@8###M@###M##########|!t*Z#N####8##M8Z@ZZ#M###@#W#####K###W# 
                                        WVd4M######@############D,\`(+KKZD#8WK#5@84VZ#WM############W## 
                                        K5WM8#8W#W########8######,,-!/))ZK5@K4)@+(/XV/Z###@###W###M#### 
                                        +8WN@##@K##W###W#########b.-.\!||\X(5)Z/7\\\t5/K########W###### 
                                        8M8###@###@##8#########KDbt! !.-!t`(-\\!.\/.\!ZdG###W#MW###G### 
                                        ~~~~~`~~~~~~~~~~~~~~~~'~` ''  ' ` ` '```
                                1 Reply Last reply Reply Quote 0
                                • JonB
                                  JonB @technoway last edited by

                                  @technoway os.abort() crashes the app, so when you launch it again, it is fresh. Not sure i follow what you mean about two windows? screenshot?

                                  cvp 1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp @JonB last edited by

                                    @JonB I think he will say that when you launch a script from the exterior (url, launcher app), during some seconds, you see another "window", the last edited file, py or txt.

                                    1 Reply Last reply Reply Quote 0
                                    • technoway
                                      technoway last edited by technoway

                                      cvp - That is what I meant. When os.abort() or os._exit(0) is called, the app shuts down, the home screen shows, but, depending on the Pythonista app, there are one or two windows running in the background.

                                      It's not a big deal. I can launch Pythonista again without closing these windows.

                                      1 Reply Last reply Reply Quote 0
                                      • Phuket2
                                        Phuket2 last edited by

                                        The os.abort() is not perfect. But could still help when setting up scripts on a friends device

                                        1 Reply Last reply Reply Quote 0
                                        • JonB
                                          JonB last edited by

                                          You are saying you see two windows from the home button menu? And click either of them reopens pythonista?

                                          Can you slowly go through step by step what you are doing to produce this behavior? i.e are you launching pythonista normally? Or using a home screen shortcut?
                                          Do you see pythonista last contents in both window? or is one of them blank?

                                          A screenshot would also go a long way to understanding this.

                                          Finally, do you need to actually terminate pythonista, or just return to the last app? There are some methods on UIapplication that let you suspend + return to last app.

                                          technoway 1 Reply Last reply Reply Quote 0
                                          • technoway
                                            technoway @JonB last edited by technoway

                                            @JonB - In every case described below, I am starting the application using a shortcut .

                                            When my app calls os._exit(0), I see no windows. If I click the home button, I see two windows in the background.

                                            I can run my application by clicking on one of the windows.

                                            If I use os._exit(0), I still see two windows, and just as before, I can still restart my app by clicking on one of the windows. (It's the mostly all white (console?) window,- my application sets a black background which shows in the other window). Note, I call console.exit(), so I though I closed the console window.

                                            I am also still able to reopen Pythonista using the Pythonista icon while that other window is present.

                                            I must not be cleaning something up?

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors