1

I am using Python's multiprocessing Process class for a project to handle a function in a separate process. My question is, what happens when does the function in a separate process do its job? Is it that the process remains idle, or is process killed by the end of the function? Also, will there be any issues with giving the process/function a heavy load?

The code block is like this:

p = Process(target=function, args=[status.json])
if not p.is_alive():
    p.start()
p.join()
skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Evren Kutar
  • 1,173
  • 1
  • 9
  • 12

1 Answers1

2

If you're using the Process class, then the process starts when you call start(), and terminates when the target function completes, or you call the Process object's terminate() method. The process does not consume execution resources after terminating, but it will remain in the process table as a zombie process until you call join().

Regarding your concerns about putting a "heavy load" on the new process, it shouldn't have any effect. The multiprocessing library launches full-blown independent processes, so they operate largely the same as your main process does. Now whether or not the Process class is really the appropriate solution to your problem is hard to say since "heavy load" can mean many different things. If your tasks are IO intensive, the threading module may be a better choice. If you are performing the same tasks on many different objects, process pools may be a more appropriate choice. But a "heavy load" in and of itself shouldn't cause problems.

Community
  • 1
  • 1
skrrgwasme
  • 9,358
  • 11
  • 54
  • 84