-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathserver.py
34 lines (30 loc) · 1.13 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 *-*
import logging
import tornado.web
import tornado.httpserver
from tornado.ioloop import IOLoop
from tornado.options import options as opts
import motor
from selene import log, options, Selene, web
if __name__ == '__main__':
options.setup_options('selene.conf')
if opts.logging_db:
log.configure_mongolog()
if not opts.db_rs:
db = motor.MotorClient(opts.db_uri).open_sync()[opts.db_name]
logging.info('Connected to a MongoDB standalone instance.')
else:
db = motor.MotorReplicaSetClient(opts.db_uri,
replicaSet=opts.db_rs_name).open_sync()[opts.db_name]
logging.info('Connected to a MongoDB replica set.')
http_server = tornado.httpserver.HTTPServer(Selene(db))
#tornado.web.ErrorHandler = web.ErrorHandler # Look a better way.
http_server.listen(opts.port)
logging.info('Web server listening on %s port.' % opts.port)
if opts.use_pyuv:
from tornado_pyuv import UVLoop
IOLoop.configure(UVLoop)
try:
IOLoop.instance().start()
except KeyboardInterrupt:
logging.info('Exiting with keyboard interrupt.')