I try to run a python program on my mac terminal. I want to manually terminate it by pressing "cmd + z". I openup "monitor", and I still see python-2.7 getting 8GB ram (wtf?), and using some cpu resources. How do I completely shut down this python program (I can't force quit because I also got another python program running on a different and separate terminal.
Just want to clarify my description, I ran two python programs, and in the "monitor", I see two Python-2.7 running.
I want to terminate one of the python program running in my terminal. How do I completely shut down that one (and also free up the resources that it is using).
cmd + Z puts the currently-running process into the background. Ctrl+D will cause Python to exit
You can use kill with the pid of your background process to close it
You can check for the PIDS for any jobs with:
lsof +D path/folder
and then:
kill -9 PID-number
Also, ctrl+Z while the process is running can stop it as well.
You can quit a python program by typing quit() without the quotes of course. Be sure to include the parentheses.
Related
I want to write a Python script which will start a GUI program (as in, run a binary program with subprocess.run or os.system or something). The script should not block until the program is done, it should start it and then keep running.
I'm doing this on Ubuntu.
I tried subprocess.Popen, but if I run, say subprocess.Popen("gedit"), I get strange behavior. If I open the Ubuntu system monitor (process manager), I can see that the gedit process appears when I run the script, and the gedit window itself opens. But if I close the window, the process doesn't end in the system monitor. The process stays there until my python script exits.
How can I get the behavior I want? The only thing I can think of right now is to just call subprocess.run in a different Python thread, is that the only thing I can do?
Try using subprocess.call. This has worked for me before.
subprocess.call(['command', 'arguments'])
The program should end when the window is closed.
You have to kill the subprocess you've created before you exit the program.
Try this.
I have been using
Python debug and LLDB attach debug since I have code in Python and C++
I have run this multiple times. It looks like everytime there is an exception in the middle of debugging, the process doesn't get killed.
As a result, now after multiple runs, when I try to use LLDB Attach debug it shows multiple instances of the same file being run
Unable to know which is the latest process
Also how to kill processes that haven't terminated.
For reference, here's an image
Those processes can probably be termed as ghost processes. Those are caused from the previous run when one does not detach the lldb from it.
Manually searching for the process ID of those and killing them solved the problem.
List python related processes
ps -ef | grep python
Killing the ones you identify as ghost.
kill -9 <process-id>
As an alternative to command line, you should be able to see that ghost python process in the process explorer (command "Open Process Explorer"), and then use Ctrl+e to kill it.
The Ctrl+e is available in VSCode 1.75 (Jan. 2023), or right now in VSCode Insiders, with issue 119345 and PR 168943 delivered.
I have a cpu intensive script I'm running in ipython that will take several days to finish. As I'm using my computer over these days, I would ideally like to be able to pause this script using some ipython shortcut (something along the lines of ctrl+c or ctrl+z) to temporarily reclaim full computing power. Is there any way this might be done?
I'm running IPython directly in the terminal in Ubuntu 16.04.
Thanks!
Have a look at kill and signal.
Suppose you have this running in your "IPython"
import time
i = 0
while True:
print('Printing: ', i)
time.sleep(0.5)
i += 1
Now open a new terminal window and type:
kill -SIGSTOP `pgrep ipython`
If you check your IPython terminal, it has stopped printing.
If you type:
kill -SIGCONT `pgrep ipython`
Your program will continue where it was stopped.
EDIT: Please note that the characters surrounding pgrep ipython are not single quotes; they're called "backticks". You can find out how to type them for your system/keyboard layout/etc.
EDIT: The command stops and continues all IPython processes. In reality, if you want to stop/continue a specific process, you have to give it a PID. It's a good idea to put your program in a file and grep for that.
Using Linux (Ubuntu 16.04), running Emacs 24.5.1, Python 3.5.2, and IPython 5.1.0. I often work with python-mode, with a live IPython prompt running in a buffer. I commonly run a function or loop, and sometimes need to break it early to examine stuff, usually while exploring data.
However, the first time I press Ctrl-C, this works fine, and the IPython process goes back to its prompt. Unfortunately the second time I press Ctrl-C, invariably the process exits with the message,
Process Python[myscript.py] interrupt
Then if I C-c C-c again, a new IPython process is started in the same buffer. However, my process is dead and I can't examine the variables and have to re-run it from the beginning. This is very annoying! I've searched but can't figure out why it only happens the second time I press Ctrl-C.
One possibility is that the process is receiving EOF as well as SIGINT, however I don't know why or how to be sure, or how to stop it doing so.
Any ideas?
Edit: I should mention that it does not seem to matter whether I use Emacs in the terminal emulator or in the GUI. Usually I prefer using it in the terminal.
Use bash command trap to catch signal if your script is running on Linux.
I am trying to run a python script via cmd prompt on my work PC (Windows 7, Python 2.7). The script requires filepaths from different drives on my PC. I am correctly pulling all necessary filepaths and I press Enter to run the script but the script just hangs. The only thing that shows is a blinking underscore. I try to click the X to close the prompt but nothing happens.
I am not able to Ctrl+C out of the program either. I open up Task Manager and I am not able to End Task (nothing happens) or End Process (cmd.exe doesn't even show up in this tab). I also tried Start-->Run-->taskkill /im cmd.exe but nothing happens. The rest of my team has no problem with Python 2.7. The only way to get out of the frozen cmd is to hold down the power button. I do not want to have to keep going through this process especially since this is during work. I'm hoping someone will be able to help me out:
Any idea what's wrong with the version of Python I am using?
How am I able to kill cmd.exe so that I can continue normal work functions without having to hold down the power button and waiting 5-10 minutes to reboot my PC?
The filepaths I was pulling files from were through ClearCase directories. It turned out that I simply had to reinstall ClearCase. There must have been some configuration issue that was causing the cmd to hang and thus forcing a hard reboot. It's good to point out that I am no longer experiencing this problem and that nothing was wrong with the python scripts.