Search code examples
pythonjsonpycharminstance

Run parallel instances of same program on Pycharm


I have a program named Scanner.py which loads parameters from a configuration file called Config.json- is there a way in which I can run two instances of this same file parallely on Pycharm with different sets of configuration passed through Config.json.

Example: this is the Json file which is read into the Python file of Pycharm. I want various combinations of this to be run without one after the other, rather in parallel

"Traded Instrument": "STOCK",
"Start Date": "2019/01/01",
"End Date": "2022/12/20",
"Trade Start": "09:16",
"Trade End": "15:29",
"Trade End Scalp": "09:16",

I do not have clue how to get started with this, other than just using different machines, but I would need more than 3/4 instances at the same time by running Scanner.py


Solution

  • I would suggest using multiprocessing. You can create a function that accepts a configuration dict and run it with different configs.

    from multiprocessing import Pool
    
    def runner(config: dict):
        # your logic
        ...
    
    if __name__ == '__main__':
        configs = [{...}, {...}, {...}]
        with Pool(len(configs)) as p:
            p.map(runner, configs)