以root身份运行twisd,找不到模块 [英] Running twistd as root, modules aren't found

查看:28
本文介绍了以root身份运行twisd,找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Twisted 编写的简单网络服务器,我正在尝试使用 twisd 来启动它.reactor.run() 一切正常,但是当我使用 twistd -y(作为 root)时,我的直接子目录中的包都没有找到.我以 root 身份运行 twind,因为服务器运行在端口 80 上.twisd 的联机帮助页 说:

I have a simple web server written in Twisted, and I'm trying to start it up daemonized with twistd. Everything works fine with reactor.run() but when I use twistd -y (as root), none of my packages which are in direct child directories get found. I'm running twistd as root, since the server runs on port 80. The manpage for twistd says:

请注意,如果以 root 身份运行 twistd,则不会在工作目录中搜索 Python 模块.

那很好,但为什么呢?我该如何解决?扭曲似乎忽略了 --rundir . 即使我明确设置了该选项.

Well that's great but why? And how can I work around? twistd seems to be ignoring --rundir . even if I set that option explicitly.

推荐答案

一般的 UNIX 智慧是在工作目录中搜索要在 root 时执行的内容是一个坏主意.争论是它打开了木马程序的大门.在以 root 身份运行时,不会特意将工作目录添加到 Python 模块导入搜索路径中,twisdd 基本上是在尝试遵循这一智慧.

General UNIX wisdom is that searching the working directory for things to execute when root is a bad idea. The argument goes that it opens the door to trojans. In not going out of its way to add the working directory to the Python module import search path when running as root, twistd is basically trying to follow this wisdom.

正如另一位评论者所说,您可以自己明确设置 PYTHONPATH 以包含包含您的应用所需代码的目录.

As another commenter said, you can explicitly set PYTHONPATH yourself to include the directories which contain the code your app needs.

您也可以完全跳过以 root 身份运行并使用 authbind 绑定低编号端口,而无需超级用户权限.这就是我所有服务器的部署方式.

You can also skip running as root entirely and use authbind to bind low-numbered ports without having superuser privileges. This is how all of my servers are deployed.

这篇关于以root身份运行twisd,找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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