• 如何在vscode中同时运行多个文件——server/client模式——在launch.json文件中设置多个configurations再compounds


    在vscode中我们一般都是同一时间只运行一个代码,但是这种设置并不适合server/client模式,甚至有很多分布式和并行的项目需要同一时间运行多个client,针对这种情况我们可以通过设置vscode中的launch.json文件来实现。

    我们可以在launch.json文件中设置多个configurations再compounds,以此实现同时运行多个程序,这里以python项目为例,给出launch.json文件内容:

    {
        // 使用 IntelliSense 了解相关属性。 
        // 悬停以查看现有属性的描述。
        // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
    
            {
                "name": "Server Python",
                "type": "python",
                "request": "launch",
                "program": "${workspaceFolder}/server.py",
                "console": "integratedTerminal",
                "justMyCode": true,
    
                "python": "/home/devil/PycharmProjects/py/bin/python",
                "cwd": "${workspaceFolder}",
                "env": {"PYTHONPATH":"${workspaceFolder}"}
            },
    
            {
                "name": "Client Python_0",
                "type": "python",
                "request": "launch",
                "program": "${workspaceFolder}/client.py",
                "console": "integratedTerminal",
                "justMyCode": true,
    
                "python": "/home/devil/PycharmProjects/py/bin/python",
                "cwd": "${workspaceFolder}",
                "env": {"PYTHONPATH":"${workspaceFolder}"}
            },
    
            {
                "name": "Client Python_1",
                "type": "python",
                "request": "launch",
                "program": "${workspaceFolder}/client.py",
                "console": "integratedTerminal",
                "justMyCode": true,
    
                "python": "/home/devil/PycharmProjects/py/bin/python",
                "cwd": "${workspaceFolder}",
                "env": {"PYTHONPATH":"${workspaceFolder}"},
            },
        ],
    
        "compounds": [
            {
                "name": "Compound",
                "configurations": ["Server Python", "Client Python_0", "Client Python_1"],
                "presentation": {
                    "hidden": false,
                    "group": "",
                    "order": 1
                }
            }
        ]
    
    }

    可以看到上面分布做了四个配置,名字为:"Server Python""Client Python_0""Client Python_1", "Compound",其中"Compound"配置是一个混合配置,该配置的执行等于同时并行执行配置"Server Python", "Client Python_0", "Client Python_1"

    在vscode的调试窗口中可以看到这个四个配置:

    按键F5,因为"Compound"执行顺序为1因此执行"Compound"配置,但是实际上执行的是"Server Python", "Client Python_0", "Client Python_1"这三个配置:

    =================================================

  • 相关阅读:
    android的FATAL EXCEPTION: main错误
    ORA12560: TNS: 协议适配器错误
    BroadcastReceiver应用详解
    using C# 详解
    mysqlproxy0.8版本读写分离测试总结
    Mysql SHOW PROCESSLIST Sending data
    [转载]大型网站运维探讨和心得
    找出并optimization表
    mysql中普通索引和唯一索引的效率对比
    ps aux 中STAT 解释
  • 原文地址:https://www.cnblogs.com/devilmaycry812839668/p/16425900.html
Copyright © 2020-2023  润新知