If my Pharo image goes into an infinite loop, how do I break out of the loop?
Asked Answered
B

2

12

Yesterday I was about 2 hours in to working on my Pharo image when I accidentally wrote some code and executed it that caused an infinite loop -- actually, I was calling one method from another method, which in turn called the original method, back and forth forever. The pharo image was unresponsive. I restarted the image and lost all my work for that two hours!

I looked online and I can hit alt-. to get into some sort of process viewer? How can I kill the infinite loop from there?

Belak answered 16/7, 2014 at 18:30 Comment(0)
R
13

Apart from interrupting an infinite loop as @Uko explained, you probably do not have lost all your work for that two hours, as you feared.

If you have killed Pharo externally without saving you could always use the

  • „Recover lost changes“ tool in the restarted image via World Menu>Tools>Recover lost changes… or
  • open the .changes file corresponding to your image in a text editor and have a look at all your past changes to the system and copy and paste some or all of them back to the running image.
Redaredact answered 16/7, 2014 at 20:27 Comment(3)
Whoa, this is very cool! So the .changes file gets written to when I make changes, even if I haven't saved the image yet?Belak
Exactly. In practice I found that it does not save all the changes that are promised in Pharo by Example, but it surely does save added or changed methods.Redaredact
Have a look at 6.10 In Smalltalk, you can’t lose code of Pharo by Example.Redaredact
L
11

You can indeed use <action key>-. (where is cmd for mac, probably ctrl for win and alt for linux (but it seams that some times is ctrl on linux and also alt on windows. For example Pharo 6.1 uses alt on win 10).

<action key>-. causes user interrupt and opens a debugger on a place that was being executed.

Longicorn answered 16/7, 2014 at 19:17 Comment(3)
Thanks Uko; could you expand your answer to explain how I could kill the offending process inside of the VM from the debugger?Belak
@SamPearson: All you have to do is close the debugger that opens when you halt execution to stop the infinite loop. Strictly speaking, while MartinW's answer is very useful, this one actually answers the question. In fact, it might be worth separating the two questions/answers to make the recovery information easier to find for others running into the same problem. Uko, it's actually Alt+. on Windows and Linux.Margetmargette
In Pharo 6.1 it's ALT-. on Windows 10.Iscariot

© 2022 - 2024 — McMap. All rights reserved.