Skip to content

Commit 8b01b6f

Browse files
author
Thomas Goodwin
committed
Added base info handler for 'hello world' and a catch for the KeyboardInterrupt on exit that almost always happened.
1 parent a570862 commit 8b01b6f

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

pyrest.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# along with this program. If not, see http://www.gnu.org/licenses/.
2020
#
2121
import os
22+
import time
2223

2324
from rest.domain import DomainInfo, DomainProperties
2425
from rest.application import Applications
@@ -33,7 +34,7 @@
3334
import tornado.httpserver
3435
import tornado.web
3536
import tornado.websocket
36-
from tornado import ioloop
37+
from tornado import ioloop, gen
3738

3839
from model.redhawk import Redhawk
3940

@@ -73,10 +74,12 @@ def __init__(self, *args, **kwargs):
7374
handlers = [
7475
(r"/apps/(.*)/$", IndexHandler),
7576
(r"/apps/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(cwd, "apps")}),
77+
(r"/client/(.*)/$", IndexHandler),
7678
(r"/client/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(cwd, "client")}),
7779

7880
# Top-level Event Handler REDHAWK status channel and event channel system
7981
# The event handler sorts out what to do for us.
82+
(_BASE_URL + _LIST + r"$", BaseInfo),
8083
(_BASE_URL + r'/(redhawk|events)', EventHandler, dict(redhawk=redhawk, _ioloop=_ioloop)),
8184

8285
# Domains, wild guess on the eventChannels one.
@@ -143,12 +146,26 @@ class IndexHandler(tornado.web.RequestHandler):
143146
def get(self, path):
144147
self.render("apps/"+path+"/index.html")
145148

149+
class BaseInfo(tornado.web.RequestHandler):
150+
@tornado.web.asynchronous
151+
@gen.engine
152+
def get(self, *args):
153+
self.write("<h1>The rest-python server is running!</h1>")
154+
self.flush()
155+
yield gen.Task(ioloop.IOLoop.instance().add_timeout, time.time()+1)
156+
self.write("<p>Now try this URL: {0}</p>".format(_DOMAIN_PATH))
157+
self.finish()
146158

147159
def main():
148160
tornado.options.parse_command_line()
149161
application = Application(debug=options.debug)
150162
application.listen(options.port)
151-
ioloop.IOLoop.instance().start()
163+
164+
try:
165+
ioloop.IOLoop.instance().start()
166+
except KeyboardInterrupt:
167+
pass
168+
152169

153170
if __name__ == '__main__':
154171
main()

0 commit comments

Comments
 (0)