0

I am trying to run a tornado webserver in the terminal, but when I run it I simply get a space which is completely empty, and then I have no way of closing the server. Right now I am trying the hello world example.

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

Any help would be much appreciated. I have already taken a look at the getting Tornado working question, and the answers there did not solve the issue.

averyrc
  • 25
  • 1
  • 6
  • If it's empty it means it's working fine.. Just go to this [location](http://127.0.0.1:8888 ) – Ajay May 24 '15 at 11:57

1 Answers1

0

All you need to do is type this URL in your browser

 http://127.0.0.1:8888

But if you do see any error messages

Try changing your port.May be it is being used by other program

application.listen(7777)

Now point your browser to

http://127.0.0.1:7777

Stopping the server

A simple ctrl+c would kill the process.But if you want to do more cleaner way

try:
    tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
    tornado.ioloop.IOLoop.instance().stop()
Ajay
  • 5,267
  • 2
  • 23
  • 30
  • could you clarify what you mean when you say "in your browser." I assume you mean something like firefox or google chrome, or am I way off here. – averyrc May 24 '15 at 12:38
  • type that url in your browser(firefox or chrome) – Ajay May 24 '15 at 12:41
  • When I try that I simply get an error that says "This webpage is not available." – averyrc May 24 '15 at 12:44
  • first: run the python script from terminal `python yourscript.py ` then point that url in your browser – Ajay May 24 '15 at 12:46
  • Thank you SO much @Ajay, that solved it. I only have one question for you. Say I wanted to make it download a file from this website, how would I do that. I am making a conversion server for school and so I would like to have the converted file download from the server. – averyrc May 24 '15 at 12:53
  • http://tornado.readthedocs.org/en/latest/guide.html Read these docs... http://tornadogists.com/ http://stackoverflow.com/questions/4212877/when-and-how-to-use-tornado-when-is-it-useless – Ajay May 24 '15 at 13:02