简体   繁体   English

在背景上的简单HTTPServer python

[英]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 /. 我尝试将它放在crontab上但找不到index.html并显示/中的文件列表。

#! /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 基本上你问的是如何从shell中分离程序...这里有几个选项

  1. ./scriptname.py >/dev/null 2>&1 & # sends the program to the background ./scriptname.py> / dev / null 2>&1&#将程序发送到后台
  2. Use gnu-screen (or similar) ... run your program via screen and you can bring it back up when you log back in 使用gnu-screen (或类似的)...通过屏幕运行你的程序,你可以在重新登录时重新启动它
  3. Daemonize your program properly 正确地对您的程序进行Daemonize

Update: 更新:

Recently I have not written a single daemon in python. 最近我没有在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 . 我目前使用supervisord并听说过关于马戏团的好东西。 These are just a small set of extra options you can use to deploy python daemons. 这些只是可用于部署python守护进程的一小部分额外选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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