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)
敬錞 潘
  • 852
  • 1
  • 14
  • 29
  • use a `thread` or `multiprocess` – vks Jun 08 '20 at 18:25
  • Perhaps `subprocess.Popen('/usr/local/bin/python3.7 -m pyxtermjs&')` –  Jun 08 '20 at 18:31
  • Does this answer your question? [How to start a background process in Python?](https://stackoverflow.com/questions/1196074/how-to-start-a-background-process-in-python) – Maurice Meyer Jun 08 '20 at 18:31

2 Answers2

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')
Red
  • 26,798
  • 7
  • 36
  • 58
1

You should use subprocess.popen, like advised here

subprocess.Popen(["/usr/local/bin/python3.7", "-m", "pyxtermjs"])
Vanillaboy
  • 388
  • 1
  • 11