Bootstrap

golang python解析器_golang python 简单异步服务器

import tornado.httpserver

import tornado.ioloop

import tornado.options

import tornado.web

import time

import os

from tornado import gen

from tornado.concurrent import run_on_executor

from concurrent.futures import ThreadPoolExecutor

from tornado.options import define, options

define("port", default=8000, help="run on the given port", type=int)

class IndexHandler(tornado.web.RequestHandler):

executor = ThreadPoolExecutor(10)

@tornado.gen.coroutine

def get(self):

print "begin"

#time.sleep(10)

yield self.pin()

self.finish()

@run_on_executor

def pin(self):

os.system("ping -c 5 www.baidu.com")

print "ping_end"

if __name__ == "__main__":

tornado.options.parse_command_line()

app = tornado.web.Application(handlers=[(r"/sleep", IndexHandler)])

http_server = tornado.httpserver.HTTPServer(app)

http_server.listen(options.port)

tornado.ioloop.IOLoop.instance().start()

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;