简体   繁体   中英

Simple HTTPServer python on background

I have this script, I do not know how to have it running in the background, cause when i close the session it close too. I tried putting it on crontab but not find the index.html and shows the list of files in /.

#! /opt/python3/bin/python3

from http.server import HTTPServer, CGIHTTPRequestHandler

port = 8000

httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
print("Starting simple_httpd on port: " + str(httpd.server_port))
httpd.serve_forever()`

Basically you are asking about how to detach the program from your shell ... here is a few options

  1. ./scriptname.py >/dev/null 2>&1 & # sends the program to the background
  2. Use gnu-screen (or similar) ... run your program via screen and you can bring it back up when you log back in
  3. Daemonize your program properly

Update:

Recently I have not written a single daemon in python. The days of forking twice or using a daemon library seem to be well behind us. I currently use supervisord and have heard good things about circus . These are just a small set of extra options you can use to deploy python daemons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM