0

I want to run my script

control_as_py

forever. I tried

while True:
    import control_as_py

but for some reasons, it runs the script ones and then stopps. How can I change that?

maki
  • 35
  • 4

1 Answers1

0

Wrap the code that you want to run inside a function.
in control_as_py

def dostuff ():
   #Write here what you want to run forever

in main.py

from control_as_py import dostuff

while True:
    dostuff()
Shuls
  • 35
  • 1
  • 7
  • But if I want to run the whole script, not just the functions? – maki Aug 26 '21 at 15:30
  • Then you can wrap the whole code of the file `control_as_py` in a `while True` loop – Shuls Aug 26 '21 at 15:32
  • okay, thanks. But can you explain why it´s not working the way I did it? – maki Aug 26 '21 at 15:40
  • From now on im just assuming, but i think it runs only once because it needs to import things in that module, so in the future its loaded. Maybe [this](https://stackoverflow.com/questions/6523791/why-is-python-running-my-module-when-i-import-it-and-how-do-i-stop-it) can help you. – Shuls Aug 26 '21 at 15:59