3

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()`

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

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.