Multiple files run in a single python instance

Hi,

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.

V.S.

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:

https://en.wikibooks.org/wiki/Python_Programming/Functions

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

https://en.wikibooks.org/wiki/Python_Programming/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):

https://en.wikibooks.org/wiki/Python_Programming/Threading

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.

https://docs.python.org/2/library/multiprocessing.html

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

Best Regards

Stephan

 

 

0

Please sign in to leave a comment.