App Engine 开发服务器在更改时不会重新加载代码

2022-01-08 00:00:00 python google-app-engine sdk devserver

问题描述

我正在开发一个将在 Google App Engine 之上运行的 python 应用程序.我使用以下目录结构设置我的应用程序:

I'm working on a python app that will run on top of Google App Engine. I setup my app up with the following directory structure:

approot/
  app.yaml
  index.yaml
  myapp.py
  controllers/
   some_controller.py
   some_controller1.py
  models/
  views/

...etc...

我的问题是,当我进行更改时,开发服务器不会总是自动重新加载我的代码,即使 Google 的文档说它会这样做.

My problem is that the development server will not always automatically reload my code when I make changes even though Google's documentation says it will.

它重新加载我的代码的唯一时间是当我所做的更改位于我的应用程序的顶级目录中时.子目录中的任何内容(例如控制器)都将被忽略.每次进行更改时,我都必须停止并启动服务器.

The only time it does reload my code is when the change I make is in the top level directory of my app. Anything in a subdirectory (e.g. controllers) is ignored. I have to stop and start the server every time a change is made.

我发现这确实阻碍了我的开发进度,特别是因为没有重启按钮,你实际上必须点击停止然后开始.

I find this really impedes my progress in development, especially since there is no restart button, you actually have to hit stop and then start.

有没有办法解决这个问题,还是我做错了?我真的很喜欢有一个组织良好的项目,并且不想将我所有的文件都转储到顶级目录中.

Is there a remedy for this or am I just doing it wrong? I really like having a well organized project and would rather not dump all my files in the top level directory.


解决方案

重载机制可能与默认导入机制和内置 __import__ 函数相关.如果您(或您的框架)以其他巧妙的方式加载模块,重新加载器可能不会注意到.一种可能的解决方法是在 myapp.py 模块中显式导入关键模块.

The reload mechanism is likely tied to the default import mechanism and builtin __import__ function. If you (or your framework) load your modules in some other, clever way, the reloader might not notice. A possible workaround is to explicitly import key modules in your myapp.py module.

相关文章