0

I have a python program called main.py program and I need to run another program in a background shell called ringToneCheck.py, so my main.py is like this:

import os
os.system("python ringToneCheck.py &")

but the problem is that when I exit my program with sys.exit() command I still have the ringToneCheck.py running in shell when I check my running processes.

what should I do to exit and kill ringToneCheck.py from my background shell completely??

M.H Mighani
  • 196
  • 5
  • 19
  • Try removing & at the end of command – Wonka Jul 30 '19 at 12:12
  • 1
    use `subprocess` module instead – Louis Saglio Jul 30 '19 at 12:13
  • 1
    when you `import` a module it actually runs it. what you can do is start a thread that imports `ringtonecheck.py` which will then die along with your main program – Nullman Jul 30 '19 at 12:13
  • 1
    There is probably a more idiomatic python way to do this, but be aware that the & at the end tells the operating system to run the command in a new process. Therefore when the main program is terminated, the spawned process stays alive. Removing the & should do it, but like i say, there may be a cleaner way. – cameron1024 Jul 30 '19 at 12:34

0 Answers0