0

I have two python files first.py and second.py, want both work in the same time so i tried to use this module import file

import first.py 
import second.py

but one only of them is working.

how to run both in the same time?

---EDIT---

i tried multi-threading and

but still no luck :(, still one of two only is working

---EDIT---

solved it was Indentation Error

dodu khaled
  • 43
  • 2
  • 7
  • Take a look at the `threading` module. Anyway, in order for your question to be answered, please clarify your question editing the answer and providing more information. – Employee Jan 15 '19 at 13:27
  • i think this may be helpful to you. https://stackoverflow.com/questions/49875889/run-two-python-files-at-the-same-time – yasara malshan Jan 15 '19 at 13:31

1 Answers1

0

You need to use threading and subprocess like this:

import threading
import subprocess
import sys

def run_process(path):
    cmd = 'python %s' % path
    process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    for line in iter(process.stdout.readline, ''):
        sys.stdout.write(line)

t1 = threading.Thread(target=run_process, args=('path_to_first.py',))
t2 = threading.Thread(target=run_process, args=('path_to_second.py',))

#start
t1.start()
t2.start()

# Waiting
t1.join()
t2.join()
  • 2
    Running a second Python instance in a `subprocess` seems excessive. Just give the second thread a function within the other module to run. – tripleee Jan 15 '19 at 13:51