重新加载 mod_fcgid 而不终止 Python 服务

发布于 2024-08-30 05:45:25 字数 441 浏览 7 评论 0原文

我目前正在学校的网络服务器上使用 FCGI 运行 Django 项目。我确实遵循了多个建议安装虚拟本地 Python 环境的指南,结果非常好。我遇到的唯一问题是“触摸”我的 fcgi 文件来重新加载源文件是不够的,但我必须通过 SSH 终止 python 服务。这是因为使用了 mod_fcgid。

然而,管理员认为我运行自己的本地 python 并不是一个好主意。他认为如果我只是告诉他要在 root 上安装哪些模块会更好,这确实是一项非常好的服务。

但是这样做,我不能再杀死Python,因为它在根目录下(虽然我很不道德,但我确实尝试过)。管理员的建议是我也应该尝试通过检查时间戳来重新加载 fcgi 脚本。我试图找到有关如何做到这一点的文档,但资金很少,而且由于我是一个绝对的初学者,我不知道什么会起作用。 有人有在 mod_fcgid 下运行 python/django 的经验吗?或者有关于在哪里可以找到相关指南/文档的提示?

I'm currently running a Django project on my school's webserver with FCGI. I did follow the multiple guides that recommends installing a virtual local Python environment and it worked out great. The only issue i had was that "touching" my fcgi-file to reload source-files wasn't enough, but instead i had to kill the python service via SSH. This because mod_fcgid is used.

However, the admin didn't think it was a great idea that i ran my own local python. He thought it better if i just told him what modules to install on root, which was a pretty nice service really.

But doing this, i can no longer kill python since it's under root(though immoral as I am, I've definitely tried). The admins recommendation was that I should try too make the fcgi script reload itself by checking time stamp. I've tried to find documentation on how to do this, but fund very little and since I'm a absolute beginner i have no idea what would work.
Anyone have experience running python/django under mod_fcgid or tips on where to find related guides/documentation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

メ斷腸人バ 2024-09-06 05:45:25

这就是我要做的:

## top of my .fcgi script
import sys, time
original_modules = sys.modules.copy()

## in a separate thread
old_ctime = os.path.getctime("mymodule.py")
while True:
    time.sleep(10)
    new_ctime = os.path.getctime("mymodule.py")
    if new_ctime > old_ctime:
        sys.modules = original_modules # reset all imports
        import mymodule
        mymodule.dofcgi()

当然这不是完美的(您可能不得不弄乱线程),但它应该让您了解如何完全“重新加载”模块。

here's what I would do:

## top of my .fcgi script
import sys, time
original_modules = sys.modules.copy()

## in a separate thread
old_ctime = os.path.getctime("mymodule.py")
while True:
    time.sleep(10)
    new_ctime = os.path.getctime("mymodule.py")
    if new_ctime > old_ctime:
        sys.modules = original_modules # reset all imports
        import mymodule
        mymodule.dofcgi()

granted this isn't drop-in perfect (you might have to mess w/ the threading) but it should give you a general idea of how to "reload" a module completely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文