Python多处理模块Windows,通过创建新进程产生新的控制台窗口 [英] Python multiprocessing module, Windows, spawn new console window with the creation of a new process
问题描述
我对此进行了一些研究,发现了一些类似的问题,但没有一个回答我真正想要的.我了解如何使用 multiprocessing
模块创建和使用流程.但是,当我创建一个新进程时,我想产生一个新的控制台窗口,仅用于该进程的使用,打印等,以便子进程不共享父进程的控制台窗口.使用 multiprocessing
模块可以做到这一点吗?
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?
推荐答案
如果您要生成一个新的控制台窗口,那么您将启动一个新的Windows控制台进程以及其中运行的新python进程.
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.
所以简短(无助)的答案是 multiprocessing
将不会执行此操作,因为它只会生成python进程.
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;
-
您使用
multiprocessing
,每个进程都会创建一个Tkinter
窗口,显示所需的文本.此问题有一个发送logging
输出的示例到Tkinter
窗口.我建议使用python附带的Tkinter
,您可以使用PyQt
,wxWidgets
等.
You use
multiprocessing
and each process creates aTkinter
window displaying the text you desire. This question has an example for sendinglogging
output to aTkinter
window. I'm suggestingTkinter
as it already comes with python, you could usePyQt
,wxWidgets
etc.
您使用 子过程
生成一个完全独立的新python进程(或控制台窗口+进程).请注意,您将无法通过这种方式轻松地 .join()
或共享线程状态.此问题提供了有关如何创建新的python线程和窗口.
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.
这篇关于Python多处理模块Windows,通过创建新进程产生新的控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!