0

is there any way i can run another python program in a new shell/window using another currently active python program for example

#file1.py is executing a loop>>>
for I in range (0,9):
    #the thing here I wish to do is 
    while I==5:
    #open file2.py in new python shell in a new window and the for loop moves on 

Note >>>I do not want the loop to wait for file2.py to do its work i wish to run both file2.py and file1.py executing at the same time
i tried using "subprocess" and it made file2.py run in same window(shell) which in turn caused file1.py to wait until file2.py did its job

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
  • 3
    You can make python subprocesses non blocking. https://stackoverflow.com/questions/16071866/non-blocking-subprocess-call – BlueBuffalo73 Aug 13 '21 at 18:28
  • You could probably import both file1 and file2 into say file3 and then use multithreading in file3 to create 2 threads to run each loop at the same time. – Mannan Bhardwaj Aug 13 '21 at 18:39
  • do you need the files to interact with any variables / return any results? if they just need to run in the background, I would personally organize a "main" function for each file, and import it and run it with a daemon thread: `from myfile import main; from threading import Thread; Thread(target=main, daemon=True).start()` – Aaron Aug 14 '21 at 02:49

0 Answers0