N
N
Northxstar2019-02-23 18:43:30
Python
Northxstar, 2019-02-23 18:43:30

How to correctly stop a Process in multiprocessing?

We have the simplest use of the multiprocessing module:

from multiprocessing import Process
pr=Process(target=MY_FUNCTION)
pr.start()

When trying to stop this miracle through pr.terminate() we have:
...
pr.terminate()
print (pr.is_alive())
>>> True

Plus, the PID is saved and it is not possible to restart via pr.start(). You
need the ability to restart via .start() and a way to determine the current status of the process, i.e. so that through .is_alive() it is clear what state it is in

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question