Python http server 与 nohup 使用时无法打印日志的问题

wpadmin~January 6, 2020 /System Management

Python http server 与 nohup 使用时无法打印日志的问题


nohup python -u -m http.server 2>&1 &

By default, Python’s stdout and stderr are buffered. As other responders have noted, if your log files are empty then (assuming your logging is correct) the output has not been flushed.

The link to the script is no longer valid, but you can try running your script either as python3 -u or the equivalent PYTHONUNBUFFERED=x python3 This causes the stdout and stderr streams to be unbuffered.

A full example that uses the standard library’s http.server module to serve files from the current directory:

PYTHONUNBUFFERED=x python3 -m http.server &> http.server.log & echo $! >

All output (stdout & stderr) is redirected to http.server.log, which can be tailed, and the process ID of the server is written to so that you can kill the process by kill $(cat


Leave a Reply

Your email address will not be published. Required fields are marked *