-4

this is my code,the problem I'm facing is that only one code will run, in order for the next to work the first must be closed, how do I run both codes separately

if Start == "Y":
    print=("starting Scrcpy")
    import os
    os.system("./sndcpy.sh")
    import os
    os.system("scrcpy")
Mike67
  • 11,175
  • 2
  • 7
  • 15
xellerate
  • 1
  • 3
  • You only need to `import os` once. Does each command run if you remove the other from the python code? – Mike67 Jul 30 '20 at 16:10
  • scrcpy is a program launched from the terminal, and sndcpy is an extension of that run from an sh file, but i can run the command properly because in order to start the other linux command i have to stop the one that is currently running, but i want each code to run seperatley without interfering with each other – xellerate Jul 30 '20 at 16:16

1 Answers1

0

You can use multithreading or multiprocessing module for that or add & to end of each command so they will run in the background, but I'm not sure if that's the best way though.

DeBos
  • 176
  • 1
  • 13
  • how would i use the multithreading command – xellerate Jul 30 '20 at 16:17
  • You can create the `Thread` and then run command inside it, but after longer research I see that there is better way to do it. You can use `subprocess` module like that: `subprocess.Popen(['command', 'arg1'. 'arg2', ...])` – DeBos Jul 30 '20 at 16:20
  • the command im using is infiniete as in it dosent end unless i physiclly turn it of – xellerate Jul 30 '20 at 17:00