简体   繁体   English

调用子进程后脚本不继续

[英]Script does not continue after calling subprocess

I have this python script which is running and I call a subprocess to run a game server.我有这个正在运行的 python 脚本,我调用了一个subprocess进程来运行游戏服务器。 The thing is I need the script to continue while the server is running.问题是我需要脚本在服务器运行时继续。 But as soon as the sub process starts, and the server starts running, the script is paused until I shut down the game server.但是一旦子进程启动,服务器开始运行,脚本就会暂停,直到我关闭游戏服务器。

How can I allow the script to continue after the server has been initialized?服务器初始化后如何让脚本继续运行?

command = f'f:&cd {server_path}&{exec_prop}'

process = subprocess.Popen(command , stdout=subprocess.PIPE , shell=True) 
    process.communicate()

communicate blocks until the process terminates. 通信块,直到进程终止。 Since this is not want you want, remove that line.由于这不是您想要的,请删除该行。 It does not seem like you are using it to actually communicate anyway in your example.在您的示例中,您似乎并没有使用它来实际进行通信。

On a side note, if you can avoid shell=True that is usually considered better practice.附带说明一下,如果您可以避免shell=True通常被认为是更好的做法。 The stdout redirection seems unnecessary as well since you are not communicating.. stdout重定向似乎也没有必要,因为您没有进行通信..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM