I've searched in a lot of places but I can't seem to get the keywords correct. I have a stalling process in Python in Sublime that causes the beachball of death on a Mac. I can't access the Tools > Cancel Build button and Control + C doesn't work. How do I kill this process?
This answer is specific to python and windows. I am not sure if there is a mac equivalent.
A running python script can be terminated from the task manager. Use Ctrl+Shift+esc
to open the Task Manager. Go to the processes
tab and kill python.exe
by simply pessing del
. This would only terminate the script and leave sublime untouched.
I have not found a way to kill a process in Sublime without killing all of Sublime. But I did find a way to make killing and reopening Sublime much less painful. Here is my way.
Many people think reopening Sublime is pain in the butt because they have to navigate to the Applications Directory with their mouse, a process which takes about 10 - 30 seconds. I used to find this annoying, so I set it up so that I could reopen sublime with five keystrokes, and it takes me about three seconds.
First, I installed Alfred. In this case, you only need the free version of Alfred.
With Alfred installed, do the following:
So, in total, once I start a process that freezes Sublime, I do the following 10 keystrokes:
Cmd-option-escape enter enter option-spacebar s u enter
This procedure does leave the Force Quit Applications window hanging around, because I have not found a quick way to get rid of it without adding ten extra keystrokes to my system. If it really bugs me, I click on the window and do cmd-w, which closes the window.
The other annoying thing is that it takes a couple of seconds for Sublime to relaunch, so usually I don't bother to run things from within Sublime. Instead, I go over to the terminal and run things there, so that I can Ctrl-C the script I'm testing without affecting Sublime.
Additionally, there is a keyboard shortcut for the Tools > Cancel Build option. I have never used it, but using it and fixing problems with it is discussed in this forum post.
I found an interesting way to solve this.
My build system on sublime-text2 call my Makefile which has 2 options and uses the ONESHELL directive:
.ONESHELL:
run: myprogram
./myprogram &
echo $$! > "pid.tmp"
Note that after it starts my program its pid is saved on a file. And i have a second option:
stop:
kill -9 `cat pid.tmp`
rm pid.tmp
This option kills the process started by the run
command.
Then i configured my build system (Tools -> Build System -> New Build System...) so i could access both options:
{
"cmd": ["make"],
"variants":
[
{
"name": "Run",
"cmd": ["make", "run"]
},
{
"name": "Stop",
"cmd": ["make", "stop"]
}
]
}
But i want to call both options from key bindings on sublime so i edited the file "Preferences -> Key Bindings - User" to look like this:
[
{ "keys": ["ctrl+r"], "command": "build", "args": {"variant": "Run"} },
{ "keys": ["alt+r"], "command": "build", "args": {"variant": "Stop"} }
]
Now if i press ctrl+r my program starts (and enters an infinity loop) and when i press alt+r my program stops which is almost what i wanted.
The only problem left is that when i run alt+r i loose the output produced by ctrl+r.
Edit: Other way i found was to start my program on a new xterm process on the Makefile:
run:
xterm ./myprogram
I can close it with ctrl+c and it wont stop sublime from working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With