1

I want to use command to launch server in python code, but main program stop here.

How to modify code to let server launch then continue my main program code.

This is my python code below.

import os
os.system('/usr/local/bin/python3.7 -m pyxtermjs')
print("Hello")  

This is my console output below

serving on http://127.0.0.1:5000
 * Serving Flask app "pyxtermjs.app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
3
  • use a thread or multiprocess Commented Jun 8, 2020 at 18:25
  • Perhaps subprocess.Popen('/usr/local/bin/python3.7 -m pyxtermjs&') Commented Jun 8, 2020 at 18:31
  • Does this answer your question? How to start a background process in Python? Commented Jun 8, 2020 at 18:31

2 Answers 2

3

You can use a Thread to multiprocess:

import os
from threading import Thread

def pro(): # Define a function to add to the Thread
    os.system('/usr/local/bin/python3.7 -m pyxtermjs')

program = Thread(target=pro) # Define the Thread with the function

program.start() # Start the Thread

print('Hello World')
Sign up to request clarification or add additional context in comments.

Comments

2

You should use subprocess.popen, like advised here

subprocess.Popen(["/usr/local/bin/python3.7", "-m", "pyxtermjs"])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.