0

I have 2 different python scripts, the first called main.py and the second called running.py

the main.py script is the following:

#setting things up and stuff
while True:
    #stuff
    Here running.py should be started
    #stuff

while running.py contains the following

#various imports
while True:
    #stuff

My question is, how can i run running.py from main.py as a new thread knowing only the name of the running script?

I looked a bit into it and, since i need to communicate and share data between main.py and running.py, I don't think creating a subprocess is the best course of action but I haven't found a way to run a whole script in a thread only knowing the script's name.

For various (stupid) company reasons I can't change the content of running.py and i can't import it into main.py so creating a threading class inside it is not a possibility but i have free rein on main.py

Is what i'm trying to do even possible?

John Doe
  • 1,613
  • 1
  • 17
  • 35
  • Possible duplicate of [Calling an external command in Python](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python) – Tomerikoo Jul 22 '19 at 22:42
  • Sounds like [subprocess module](https://docs.python.org/library/subprocess.html) is what you need... – Tomerikoo Jul 22 '19 at 22:43
  • @Tomerikoo i need the two scripts to share memory space and as far as i know this is not possible with a subprocess – John Doe Jul 23 '19 at 12:34
  • In that case, look at the second answer in the duplicate link which list alot of ways of doing what you need, and then consider using a thread with one of those methods as threads share memory – Tomerikoo Jul 23 '19 at 12:38
  • @Tomerikoo so you are saying something like starting a subprocess inside a thread from the main.py file so that, while being two different processes, they share memory because one is inside a child thread of the other? How ould one go about doing so? I really don't understand how it could be written so that it works. – John Doe Jul 23 '19 at 12:44
  • First of all as a disclaimer I don't have much experience with those things and merely offering advice on how to continue research. What I meant is leave the `subprocess` option all together, and from the `main.py` create another *thread* that calls the sccript using for example `os.system` and that way they will share memory. Again, smply offering advice this is why it's a comment and not an answer... – Tomerikoo Jul 23 '19 at 12:51

0 Answers0