Python 为udp打开多个cmd提示
Python open multiple cmd prompts for udp
我正在尝试 运行 一个 python 脚本,该脚本打开 2 个命令提示符来模拟 udp 的客户端和服务器。基本上,我想要这样的东西
os.system('cmd /k "python server.py"')
os.system('cmd /k "python client.py"')
我可以 运行 单独的脚本来让它工作,但我想要一个脚本来执行整个事情。
我建议您按以下方式使用线程:
import threading
import os
def server():
os.system("python server.py")
def client():
os.system("python client.py")
def main():
server_thread = threading.Thread(target=server)
server_thread.start()
client_thread = threading.Thread(target=client)
client_thread.start()
我正在尝试 运行 一个 python 脚本,该脚本打开 2 个命令提示符来模拟 udp 的客户端和服务器。基本上,我想要这样的东西
os.system('cmd /k "python server.py"')
os.system('cmd /k "python client.py"')
我可以 运行 单独的脚本来让它工作,但我想要一个脚本来执行整个事情。
我建议您按以下方式使用线程:
import threading
import os
def server():
os.system("python server.py")
def client():
os.system("python client.py")
def main():
server_thread = threading.Thread(target=server)
server_thread.start()
client_thread = threading.Thread(target=client)
client_thread.start()