5

I've done some research on this and found somewhat similar questions but none answer what I'm really looking for. I understand how to create and use processes with the multiprocessing module. But when I create a new process, I would like to spawn a new console window just for the use of that process, for printing and so on, so that the child processes don't share the parent process's console window. Is there a way of doing that with the multiprocessing module?

Ray
  • 7,833
  • 13
  • 57
  • 91
  • I have no idea how to do that. I'm curious though why you would need a new console window for a child process. Seems a rather odd thing to be doing with the multiprocessing module. – Jason White Feb 18 '13 at 14:27

1 Answers1

5

If you're going to spawn a new console window, then you're starting a new Windows console process as well as the new python process running inside it.

So the short (and unhelpful) answer would be that multiprocessing won't do this as it only spawns python processes.

However, I can see two ways around this;

  • You use multiprocessing and each process creates a Tkinter window displaying the text you desire. This question has an example for sending logging output to a Tkinter window. I'm suggesting Tkinter as it already comes with python, you could use PyQt, wxWidgets etc.

  • You use subprocess to spawn an entirely separate and new python process (or console window + process). Note that you won't be able to .join() or share thread states easily this way. This question has an example of how to create a new python thread and window.

Community
  • 1
  • 1
danodonovan
  • 19,636
  • 10
  • 70
  • 78
  • 1
    OK thank you! Very concise. I guess I'll use the GUI solution as my application needs child processes to share data easily. – Ray Feb 18 '13 at 15:02
  • 1
    Suppose you spawn new console windows from the the parent process (`os.system("start cmd.exe"`)). Is there a way to specify and assign the output stream of select children processes to select console windows? – Minh Tran Jul 15 '18 at 17:17