Pythonista hung- can't stop program. Stop (X) button was disabled
After stopping execution of the script (below) while it was running, the stop(X) button was permanently disabled, and the Start (Right Arrow) button was not visible.
Attached are Dropbox links for the script and a screenshot, showing the state of the Stop button.
Please let me know if these links do not work (IS THERE A WAY TO ATTACH FILES IN THIS FORUM?????)
This script does nothing useful, it was just a simple example to type in to give Pythonista a test.
Normally, I would have added a Ctrl-C exception handler to exit gracefully by manually stopping the thread. Since there is no Ctrl key on an iPad I can't implement Ctrl-C.
Exiting Pythonista did not help. I had to reboot the iPad.
@ahenry91 I think he's saying that although it appears not to be disabled, it's not doing anything.
If you look at the console view on the side, the [X] is able to be pressed.
The X button on the right side (console window) did not respond, it acted like it was disabled.
What is the difference between the X button above the Code window (the one that appears after Start is pressed), and the X button in the console window.
Chances are- in order to duplicate the issue I saw, you may have to run the script and stop it manually, before the thread exits, several times before you see this problem. (That is, run the script, wait until you see some output in the console, and Press X)
Of course, duplicating this issue is likely to be related to background activity in iOS.
I'm running an iPad Air264GB, with iOS 9.2
Second, to quit the app, double-click the home button. You'll see all your recent apps. When you see Pythonista, swipe up on the window >to quit the app. Now, when you return to the app, your problem should be solved.
Will try tonight when I get home. I know how to catch KeyboardInterrupt, I just didn't know how to send Ctrl-C
Notice that the X button above the code Window is disabled.
The X button above the console appears to be enabled, but has no effect.
Also note that I intentionally entered 1/0 in the console prompt, hoping to force a DivisionByZero exception. No affect, the exception was not raised (at least in the current thread)
I caught the KeyboardInterrupt in the threads just to keep it from printing the interrupt error message.
But the time.sleep(1) at the end keeps the main thread alive allowing the KeyboardInterrupt to kill the script. I tested this on my iPad (which has the same specs as yours) and was able to kill the script each time.
Second, to quit the app, double-click the home button. You'll see all your recent apps. When you see Pythonista, swipe up on the window >>to quit the app.
Are you stating that if I don't swipe to remove an app, that it will continue running in the background?
If so, I wasn't aware of this.
@cappy If you don't swipe to remove an app, the app remains running in the background for a short time.Swiping to remove an app won't completely stop background processes, but will stop the main app.
Cases in which it won't stop include, for example, your mail client that listening for new emails in the background.
Not swiping away an app also does not guarantee that it will keep running. When iOS needs RAM, it quits background apps that you haven't used recently. The only way to keep an app permanently open is by making it play "music" or use the microphone or something.
@Webmaster4o I may be wrong, but when you swipe away an app I think you'll only receive push notifications, which are handled by a standard system service, and not by an app-specific background process. The built-in Mail app has the ability to check for mail every x minutes even when the main app isn't running in the background, but I think that's something only Apple can do.
@dgelessus No, I see it in other apps. I can quit the app, but still receive notifications. The following come to mind as apps I've used over the years with the ability to check for updates in the background when quit:
- Inbox by Gmail (my email client)
- Trivia Crack
- Clash of Clans
- YouTube (It can send notifications when subscribed accounts publish videos)
These all send notifications which are obviously not pre-scheduled because they rely on external events as triggers for these notifications.
@Webmaster4o Those apps don't have to be running for you to get notifications. The notifications are sent by some server (e.g. Twitter) to an Apple server, and that Apple server delivers all notifications to your device. A system service is listening for notifications, regardless of which apps are running.
@omz Wasn't aware of that. I thought they all implemented their own background processes. That's pretty neat.
From my experience if the stop button in the console doesn't seem to work (seems to be an intermittent bug), swiping back to the script page and hitting the stop button there usually works.
swiping back to the script page and hitting the stop button there
What do you mean? The script page was visible, no swiping was needed.
@cappy Oh. apologies. I figured you were on the console since it automatically slides out when a script is run as opposed to the actual editable script "code" page. Sometimes the x button on the console page (which presumably is supposed to mirror the button on the code page) doesn't do so.
I think calling exit() in the thread isn't a good idea. Better to let main exit under controlled conditions in case some cleanup is needed.
I ended up adding a KeyboardInterrupt handler in the thread AND in main().
You don't know where the execution will be when Ctrl-C is sent. I wanted both bases covered.
The Ctrl-C handler in the thread simply prints a message (so I know which handler caught the Ctrl-C), then calls self.stop(). The thread just exits gracefully.
In main, the Ctrl-C handler checks if the thread is running, if it is, self.stop() is called, a message is printed, the loop broken out of.
Sorry I didn't paste my code, I had to fix a broken drawer last night. It took longer than expected (but my head was thinking about this thread hang issue) ;-)
I didn't see the original hang problem, but when I run my solution, 1 out of 6 times I do see an exception related to the thread switching.
I hope to paste that code tonight.
I need to run at least 20+ times to make sure the hang doesn't occur again.
Here is a link to my current code, with the Ctrl-C handlers added.
I haven't been able to duplicate the unresponsive X button with this code as of yet,
but I do see an occasional exception.
Dang- I forgot about this dorky forum software- not taking attachments. Can we get some decent forum software going here so we can post attachments directly??
This is really annoying.
Here's the exception screenshot
Here's the current code