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
2
Answers
I would suggest using multiprocessing. You can create a function that accepts a configuration dict and run it with different configs.
I would say in your case it’s better to make a multi-thread wrapper, simply because threading uses the same memory space, and no awaiting or such is required, whereas multi-processing uses a different memory space.
NOTE: there is a drawback to using threading, where it is not memory safe (mostly), and you cannot interrupt the program when it is doing the processing, unless you make a sort of check inside the function.
The program will look like this if you want it to work with keyboard interrupts: