Stop sublimated text while executing an infinite loop

When I do something like

while True: print('loop') 

and execute this code in an elevated state, I cannot stop it. I have to manually kill the process and restart the sublime.

Is there a way to set some kind of 'max_execution_time' or any other workaround that allows us to stop this?

+13
python sublimetext3
source share
6 answers

You want to use Ctrl + Break . For your own information, just go to the " Tools" section in Sublime Text and you will see "Unassemble" and the above hotkey. This will work well for infinite loops. Suffice it to say, I had the same thing! ;)


For Windows users, there is no Break key, so go to Settings> Key Bindings and change the line

 { "keys": ["ctrl+break"], "command": "cancel_build" } 

to another shortcut like Ctrl + Alt + B

+26
source share

For me (on Linux), there is no break key on the keyboard, and this shortcut is somehow related to another combination: ctrl + alt + c .

You can find where it is connected in the Tools menu:

enter image description here

After interrupting your script, you should see the text [Cancelled] printed on the sublimetext console.

+2
source share

You have a couple of options. You can set up a huge number of iterations (I actually do this with most loops until I completely debug the code to avoid endless loop loops): So, for example,

 max_iterations = 100000000 while i < max_iterations: print("Hello World") 

An alternative would be to use a temporary module to synchronize the runtime of your code like this

 import time max_execution_time = 10000000 #this will be in seconds start_time = time.clock() elapsed_time = 0 while elapsed_time < max_execution_time: elapsed_time = time.clock() = start_time #Your loop code here 
+1
source share

For MacOS:

 cmd + option + esc 

get out

+1
source share

The combination of ctrl+break .

There is no break button on Windows, so you can go to " Preferences > Key Bindings and add on the user side:

{ "keys": ["ctrl+c"], "command": "cancel_build"}

Now, by pressing Ctrl + C, execution will stop. Of course, you can change the combination to what you want.

0
source share

Just press CTRL + C on MacOS.

0
source share

All Articles