python - 在网络服务器上运行 python 脚本(后台)
问题描述
我目前正在创建一个制作“统计信息”的脚本,它必须不断运行,我想将它上传到我的网络服务器(它有 cPanel)上运行,而不是在我的计算机上运行。我希望它在后台运行,所以我不需要打开任何网页或其他任何东西。那可能吗?
解决方案
主管是一个很好的方法来做到这一点。
http://supervisord.org/ 这允许您在启动时像服务一样运行脚本。还允许您指定命令行选项并指定日志记录。有自动重启的选项。
示例配置:
[program:test]
command=/usr/bin/python /home/ubuntu/test.py
directory=/home/ubuntu
autostart=true
autorestart=true
startretries=3
stderr_logfile=/home/ubuntu/test.err.log
stdout_logfile=/home/ubuntu/test.out.log
user=ubuntu
如果您希望在 Web 服务器的上下文中运行它,您可能还希望使用 Django,它是一个用于网站/应用程序的 Python Web 框架。然后你可以使用 Celery 来安排你的 Python 函数。 https://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
推荐阅读
- python - 机器学习 Sololearn 关于 Coulmn 数据等的 Coach 问题
- c++ - 无法理解 OBS-Studio 源代码中的 typedef 指针函数声明
- vbscript - 经典 ASP 解码
- python - 我无法使用脚本登录
- node.js - 将多个范围 (ACL) 中间件传递给路由只是测试第一个范围
- java - 找不到方法错误的实现方法
- blazor - Blazor 声称传输用户名 var 的问题
- reactjs - ReactJS 应用程序不断被部署到 Heroku,使用开发版本而不是生产版本
- c++ - C++如何同时运行2个boost:asio:io_context
- java - Android listView 适配器是否应该有 api 调用