I have two python files in the same directory.
File 1: main.py
import time
import threading
from subprocess import call
def thread_second():
call(["python", "python_test.py"])
processThread = threading.Thread(target=thread_second) # <- note extra ','
processThread.start()
time.sleep(2)
print ('the file is running in the background')
print('exit main')
File 2: secondary.py
import time
import os
try:
file = open("runnnig.tmp","x")
file.close()
except Exception as FileExistsError:
print('file already exists')
print('Secondary file is running')
# do some staff
time.sleep(10)
What I am trying to accomplish is to run the secondary.py from main.py. Only one problem I want the secondary.py to run completely independent of the main.py so that after opening the secondary.py the main.py exits. With this solution here, that I found here the secondary.py starts running normally but the main.py hangs until the secondary.py exits. How can I accomplish that?
PS. For anyone wondering what I am trying to do
I have a node.js server running on a Raspberry pi. When a request is given to the server the main.py is called from the server. The secondary.py is a script that tells raspberry to start logging values from a sensor. The secondary.py will run an infinite loop until another script interrupts it. That's why I don't want the main.py to hang until the secondary.py exits