Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I kill a Python multiprocessing job?

In reference to this question I had asked, I can successfully run jobs using multiprocessing and I can see that all processors are being utilized. How do I kill this job? From terminal I run:

python my_multiprocessor_script.py

Then I hit Ctrl+C to kill.

However the job doesn't seem to be killed and I can see all the processors still in use. I'm running Red Hat Enterprise Linux Server release 6.6.

like image 864
ADJ Avatar asked Apr 29 '15 20:04

ADJ


People also ask

How do you kill a Python process that is running?

Alternatively, you can use the top command to find the python process. Simply enter k (for kill) and the top program will prompt you for the PID of the process to kill.

How do you close a Python pool?

You can shutdown the process pool via the Pool. close() or Pool. terminate() functions.

What is lock in multiprocessing in Python?

Python provides a mutual exclusion lock for use with processes via the multiprocessing. Lock class. An instance of the lock can be created and then acquired by processes before accessing a critical section, and released after the critical section.

How does multiprocessing in Python work?

multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads.


1 Answers

You should be able to do something like this.

Original Author

kill -9 `ps -ef | grep my_multiprocessor_script.py | grep -v grep | awk '{print $2}'`

also take a look at Python Multiprocessing Kill Processes for more info

like image 181
MZaragoza Avatar answered Sep 23 '22 22:09

MZaragoza