如何在后台运行 Flask Server [英] How to run Flask Server in the background

查看:39
本文介绍了如何在后台运行 Flask Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的 Rapsberry Pi 上设置了 Flask,我使用它的唯一目的是充当我使用 Python 脚本创建的 xml 文件的服务器,以将数据传递到 iPad 应用程序 (iRule).

I have set up Flask on my Rapsberry Pi and I am using it for the sole purpose of acting as a server for an xml file which I created with a Python script to pass data to an iPad app (iRule).

我的 RPI 设置为无头,我的访问是通过 Windows 10 使用 PuTTY、WinSCP 和 TightVNC 查看器.

My RPI is set up as headless and my access is with Windows 10 using PuTTY, WinSCP and TightVNC Viewer.

我通过打开终端窗口和以下命令来运行服务器:

I run the server by opening a terminal window and the following command:

sudo python app1c.py 

这设置了服务器,我可以很好地访问我的 xml 文件.然而,当我关闭 Windows 机器和 PuTTY 会话时,Flask 服务器关闭!

This sets up the server and I can access my xml file quite well. However, when I turn off the Windows machine and the PuTTY session, the Flask server shuts down!

如何设置才能让 Flask 服务器在 Windows 机器关闭时继续运行?

How can I set it up so that the Flask server continues even when the Windows machine is turned off?

我阅读了 Flask 文档:

I read in the Flask documentation:

虽然轻量级且易于使用,但 Flask 的内置服务器不适合生产,因为它不能很好地扩展,并且默认情况下一次只处理一个请求.

While lightweight and easy to use, Flask’s built-in server is not suitable for production as it doesn’t scale well and by default serves only one request at a time.

然后他们继续举例说明如何将您的 Flask 应用程序部署到 WSGI 服务器!鉴于我正在处理的简单应用程序,这是否有必要?

Then they go on to give examples of how to deploy your Flask application to a WSGI server! Is this necessary given the simple application I am dealing with?

推荐答案

使用:

$ sudo nohup python app1c.py > log.txt 2>&1 &

nohup 允许运行命令/进程或 shell 脚本,这些脚本可以在您从 shell 注销后继续在后台运行.

nohup allows to run command/process or shell script that can continue running in the background after you log out from a shell.

<代码>>log.txt:将输出转发到该文件.

> log.txt: it forword the output to this file.

2>&1:将所有的 stderr 移到 stdout.

2>&1: move all the stderr to stdout.

最后的 & 允许您在当前 shell 的后台运行命令/进程.

The final & allows you to run a command/process in background on the current shell.

这篇关于如何在后台运行 Flask Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆