我可以仅将 Python .pyc 文件部署到 Google App Engine 吗?
我正在开发一个在 Google App Engine 上使用 Django 的项目。有人问我是否可以将某些代码仅部署为已编译的。
所以我想问题是我可以上传一个仅包含相关代码片段的 .pyc 文件吗?我已经在应用程序中使用views.pyc 文件进行了基本测试,但结果不起作用。是否可以设置一些配置或其他配置来允许 Google App Engine 仅使用 .pyc 文件?
I'm working on a project utilizing Django on Google App Engine. I've been asked if some of the code can be deployed as compiled only.
So I guess the question is can I upload a .pyc file only that contains the piece of code in question? I've done a basic test with a views.pyc file in an application and things don't work. Is there some configuration or other that I can set to allow Google App Engine to just use the .pyc files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我意识到当你问这个问题时你无法做到这一点,但现在你可以,如果你使用Python 2.7。请参阅 Python 2.7 中的沙盒:
I realise you couldn't do this when you asked this question, but you can now, if you use Python 2.7. See Sandboxing in Python 2.7:
不,你不能 - 你只能上传源代码。但是,没有充分的理由这样做:您的代码将在需要时在服务器上进行字节码编译,并且在任何情况下都没有人能够访问您的代码。
No, you can't - you can only upload sourcecode. There's no good reason to do this, though: your code will be bytecode-compiled on the servers when needed, and nobody is able to access your code in any case.
你为什么要这么做?因为您的 .py 文件会上传到 Google 基础设施,只有在您明确授予权限的情况下才能看到。
但是,是的,没有理由只上传 .pyc 文件不应该工作。如果您在开发环境中尝试一下,您会发现它的工作原理就像 BaseHTTPServer 可以将 python 编译的模块作为处理程序一样。
此外,最近的 GAE 支持 python 文件的自动预编译,这意味着只要您更新应用程序,python 文件就可以预编译并提供服务。因此,如果希望在应用引擎端检查 .py 文件,您可能需要在 appcfg.py 上传期间使用
--no_precompilation
。Why would you want to do that in the first place? Because your .py files are uploaded to Google infrastructure and can be seen only if you explicitly give permissions.
But yes, there is no reason as why uploading only .pyc files should not work. If you try it, in your dev environment, you will find it working just as BaseHTTPServer can take python compiled modules as handlers.
Also, recent GAE supports automatic precompilation for python files, which means that as soon as you update your application, the python files can precompiled and served. So, you might have to play with
--no_precompilation
during appcfg.py upload if there was any expectation to check for .py files at the app engine end.