【问题标题】:Run python script on webserver (background)在网络服务器上运行 python 脚本(后台)
【发布时间】:2019-12-10 18:15:44
【问题描述】:

我目前正在创建一个生成“统计信息”的脚本,它必须持续运行,我想将它上传到我的网络服务器(它有 cPanel)上运行,而不是在我的计算机上运行。我希望它在后台运行,所以我不需要打开任何网页或其他任何东西。这可能吗?

【问题讨论】:

标签: python webserver cpanel


【解决方案1】:

Supervisor 是一个很好的方法。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2014-03-15
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多