def get_app(self): # Usage: # Constructor for TestURLGenHandler, we will need to return the # application in order for the http server that starts up in this # class to be called. We also need to setup a momoko_db_connection using # the class's own io_loop like when we tested momoko pool in tests_database.py. # Arguments: # None # The reason that we cannot use the same momoko_pool in momoko_pool.py is that # the unit tests generates it's own io_loop in the self.io_loop variable, hence # if we don't use it, momoko.pool isn't going to run on it's io_loop. self.momoko_db_connection = momoko.Pool(dsn='dbname=%s user=%s password=%s host=%s port=%s' % (momoko_settings.dbname, momoko_settings.user, momoko_settings.password, momoko_settings.host, momoko_settings.port), size=momoko_settings.num_connections, ioloop=self.io_loop) # Call connect to establish connection with the momoko pool self.momoko_db_connection.connect() # Create an AsyncMomokoDBQueryExecutor so that we can use it's read/write functions self.db = AsyncMomokoDBQueryExecutor(momoko_pool=self.momoko_db_connection) # Create a cursor parser to get data from cursor self.cursor_parser = AsyncSQLDataParser() # Return the application to our HTTP server. return router.create_application(db=self.db, cursor_parser=self.cursor_parser)
import tornado import tornado.ioloop import tornado.web import url_server.router.router_settings as settings from url_server.router.router import create_application from logger.logger import logger as logger # main.py is the main access point of the tornado app, to run the application, just run "python main.py" # What this will do is listen to port in the settings.py file, and then we can access the app using # http://localhost:settings.port on any browser, or using python requests library if __name__ == "__main__": # Set the application to listen to port 8888 application = create_application() application.listen(settings.port) # Get the current IOLoop currentIOLoop = tornado.ioloop.IOLoop.current() # Log the port that is listened logger.info("Started application on port:" + str(settings.port)) # Start the IOLoop currentIOLoop.start()