【问题标题】:Auto reloading is not working in Bottle framework自动重新加载在 Bottle 框架中不起作用
【发布时间】:2017-06-12 08:30:18
【问题描述】:

我目前正在开始使用 Bottle 框架(做 Hello World 示例,然后必须构建一个 RESTful API)。问题是重新加载器不起作用。当我对代码进行更改并重新加载更改应该显示没有任何反应的页面时。它可以在我朋友的电脑上运行,所以我有点困惑。

使用 python 2.7。

from bottle import route, run

@route('/hello')
def hello():
    return "Hello World!"

run(host='localhost', port=8080, debug=True, reloader =True)

编辑:我还注意到,当我在服务器仍在侦听时保存脚本中的更改时,我得到了这个:

----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 60472)
Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 290, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 318, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\SocketServer.py", line 652, in __init__
    self.handle()
  File "C:\Python27\lib\wsgiref\simple_server.py", line 116, in handle
    self.raw_requestline = self.rfile.readline(65537)
  File "C:\Python27\lib\socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
KeyboardInterrupt
----------------------------------------

【问题讨论】:

  • 我很抱歉队长明显的问题,但你在重新加载页面之前保存了文件吗?如果是这样,在进行更改并刷新页面后,您是否在控制台中看到 Bottle [...] server starting up (using WSGIRefServer())...
  • 是的,我在重新加载之前确实保存了,我在命令提示符中看到的内容与您刚才所说的完全相同。
  • 你的操作系统是什么?

标签: python api web bottle


【解决方案1】:

如果您使用 Windows 操作系统,则有 an interesting clue

请记住,在 Windows 中,这必须是 在 if name == "ma​​in" 下:由于多处理的方式 模块工作。

所以它应该是这样的

from bottle import route, run

@route('/hello')
def hello():
    return "Hello World!"

if __name__ == "__main__":
    run(host='localhost', port=8080, debug=True, reloader=True)

【讨论】:

  • 我在其中一个脚本上确实有这样的情况,但行为仍然相同。最奇怪的是,昨天我不得不去某个地方,在空闲时间我试图看看它是否仍然不起作用并且它确实起作用了,我的意思是自动重新加载器)。但是现在我回到家了,我又试了一次,但它不再起作用了(我没有对代码进行任何更改)。怎么可能?
猜你喜欢
  • 1970-01-01
  • 2022-10-22
  • 1970-01-01
  • 1970-01-01
  • 2021-07-18
  • 1970-01-01
  • 2013-09-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多