Beispiel #1
0
    def run(self):
        asyncio.set_event_loop(asyncio.new_event_loop())
        tornado.platform.asyncio.AsyncIOMainLoop().install()
        #~ tornado.autoreload.start()
        #~ tornado.autoreload.watch( sys.argv[0] )

        app=tornado.web.Application([
            (r'/ws',            WebSocketHandler,dict(instance=self.instance)),
            (r'/_/(?P<url>.+)', ProxyHandler,dict(instance=self.instance)),
            (r'/guy.js',        GuyJSHandler,dict(instance=self.instance)),
            (r'/(?P<page>[^/]+)/guy.js',        GuyJSHandler,dict(instance=self.instance)),
            (r'/(?P<page>[^\\.]*)',  MainHandler,dict(instance=self.instance)),
            (r'/(.*)',          tornado.web.StaticFileHandler, {'path': os.path.join( pathToData(), FOLDERSTATIC) })
        ])
        app.listen(self.port,address=self.host)

        self.loop=asyncio.get_event_loop()

        async def _waitExit():
            while self._exit==False:
                await asyncio.sleep(0.1)

        self._exit=False
        self.loop.run_until_complete(_waitExit())

        # gracefull death
        ## tasks = asyncio.all_tasks(self.loop) #py37
        tasks = asyncio.Task.all_tasks(self.loop) #py35
        for task in tasks: task.cancel()
        try:
            self.loop.run_until_complete(asyncio.gather(*tasks))
        except concurrent.futures._base.CancelledError:
            pass
Beispiel #2
0
    def run(self):
        statics = os.path.join(self.instance._folder, FOLDERSTATIC)

        asyncio.set_event_loop(asyncio.new_event_loop())
        tornado.platform.asyncio.AsyncIOMainLoop().install()
        if self.autoreload:
            print("**AUTORELOAD**")
            tornado.autoreload.start()
            tornado.autoreload.watch(sys.argv[0])
            if os.path.isdir(statics):
                for p in os.listdir(statics):
                    tornado.autoreload.watch(
                        os.path.abspath(os.path.join(statics, p)))

        app = tornado.web.Application([
            (r'/_/(?P<url>.+)', ProxyHandler, dict(instance=self.instance)),
            (r'/(?P<id>[^/]+)-ws', WebSocketHandler,
             dict(instance=self.instance)),
            (r'/(?P<id>[^/]+)-js', GuyJSHandler, dict(instance=self.instance)),
            (r'/(?P<page>[^\.]*)', MainHandler, dict(instance=self.instance)),
            (r'/(.*)', tornado.web.StaticFileHandler, dict(path=statics))
        ])
        app.listen(self.port, address=self.host)

        self.loop = asyncio.get_event_loop()

        async def _waitExit():
            while self._exit == False:
                await asyncio.sleep(0.1)

        self._exit = False
        self.loop.run_until_complete(_waitExit())

        # gracefull death
        try:
            tasks = asyncio.all_tasks(self.loop)  #py37
        except:
            tasks = asyncio.Task.all_tasks(self.loop)  #py35
        for task in tasks:
            task.cancel()
        try:
            self.loop.run_until_complete(asyncio.gather(*tasks))
        except concurrent.futures._base.CancelledError:
            pass
Beispiel #3
0
from web import ui_methods
import tornado.httpclient
import tornado.platform.asyncio
import tornado.web
import tornado.locks
import tornado.ioloop
import tornado.concurrent
import logging
import json
import asyncio


# from modules.kinetic_core.util.TracePrints import *
# endregion

loop = asyncio.get_event_loop()

# Инициируем логгирование
Logger.init(logging.DEBUG)


class LoginHandler(BaseHandler):

    async def get(self):
        self.render("auth/login_m.html")


    @asyncio.coroutine
    async def post(self):
        from authorization.CpUserDB import CpUserDB
        db = CpUserDB()
Beispiel #4
0
class MainHandler(BaseHandler):
    @asyncio_coroutine
    def get(self):
        s = randint(0, 7)
        # print("in  ", '-' * int(s), s)
        # yield from asyncio.sleep(s)
        # print('out ', '-' * int(s), s)

        db_messages = yield from self.select(user.select())
        db_messages = [{"id": i[0], "name": i[1]} for i in db_messages]
        r = yield from self.insert(user.insert().values(name=str(s)))

        if len(db_messages) > 10:
            yield from self.insert(user.delete())
        self.render('index.html', messages=db_messages)


class Application(tornado.web.Application):
    def __init__(self):
        handlers = ((r'/', MainHandler), )

        tornado.web.Application.__init__(self, handlers)


application = Application()

if __name__ == '__main__':
    tornado.platform.asyncio.AsyncIOMainLoop().install()
    application.listen(8001)
    asyncio.get_event_loop().run_forever()
Beispiel #5
0
 def __init__(self):
     self.io_loop = asyncio.get_event_loop()
Beispiel #6
0
logging.basicConfig(level=logging.DEBUG)

log = logging.getLogger('app')

class MainHandler(tornado.web.RequestHandler):

    @tornado.web.asynchronous
    @tornado.gen.engine
    def get(self):
        b = Buzi()
        result = yield from b.call("foo", 2, 3)
        self.set_header('Content-Type', 'text/html')
        self.write(str(result))
        self.finish()

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




if __name__ == '__main__':
    tornado.platform.asyncio.AsyncIOMainLoop().install()

    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(8888)
    print('Demo is runing at 0.0.0.0:8888\nQuit the demo with CONTROL-C')
    asyncio.get_event_loop().run_forever()