3

I am currently getting started with Bottle framework (doing the Hello World example and afterwards have to build a RESTful API). The problem is the fact that reloader doesn't work. When I make a change in the code and reload the page where the change should show nothing happens. It works on my friends' computers so I'm am a bit confused.

Using python 2.7.

from bottle import route, run

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

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

EDIT:Also what i noticed is that when i save the change in the script while the server is still listening i get this:

----------------------------------------
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
----------------------------------------
JDoe
  • 53
  • 7
  • I am sorry for captain obvious question but have you saved the file before reloading the page? If so, do you see `Bottle [...] server starting up (using WSGIRefServer())...` in a console after making the change and refreshing the page? – Piotr Dawidiuk Jan 26 '17 at 21:08
  • Yes i did save before reloading and i see the exact same thing in the command prompt as you just said . – JDoe Jan 27 '17 at 14:29
  • What is your operating system? – Piotr Dawidiuk Jan 27 '17 at 16:03

1 Answers1

4

There is an interesting clue if you use Windows OS:

Keep in mind that in windows this must be under if name == "main": due to the way the multiprocessing module works.

So it should look like this

from bottle import route, run

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

if __name__ == "__main__":
    run(host='localhost', port=8080, debug=True, reloader=True)
Community
  • 1
  • 1
Piotr Dawidiuk
  • 2,961
  • 1
  • 24
  • 33
  • I do have it like that on one of the scripts and still same behaviour. The wierdest thing is that yesterday i had to go somewhere and in a bit of free time i tried to see if it still doesnt works and it did work, the auto reloader i mean) . But now i am back home and i tried again and it doesn't work anymore ( i did not make any change on the code) . How is possible? – JDoe Jan 28 '17 at 14:47