Multiple files run in a single python instance


I am looking on how to run multiple files from the pycharm IDE in a single python instance, such that they can share variables.

To clarify, I want to have a file run once (at startup) giving me some datamanager and similar things, and have scripts in other files running specific experiments, while having the possibility to add the generater data to the datamanager (from the first file).

If someone knows how I could do that, it would give to my pycharm program a real help.


1 comment
Comment actions Permalink

Hi, what you are looking for is not to be found in pycharm. But it is possible in python in general:

- simplest way is to write a function for each experiment returning its results to a central calling script (your startup script), which calls the functions sequentially and gathers their results in some kind of datastructure:

You can have the functions in one or mutiple files (modules):

If you need to execute the functions in parallel you can make use of the threading module. It will run your functions in a pseudo parallel manner (still all in one process on on cpu thread):

if you want to make use of the multiple CPUs in your system in order to speed up execution you can use the multiprocessing module. This will create a single process for each function, each running on its own CPU core, but you still have the possibility to communicate results to a central script.

Hope this info can help you. have fun with the power of python

Best Regards





Please sign in to leave a comment.