diff --git a/Procfile b/Procfile index 629b83a..1e700b4 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: python main.py +web: uwsgi --http 0.0.0.0:5050 --wsgi-file main.py --processes $SINACLOUD_CONTAINER_CPU \ No newline at end of file diff --git a/README.md b/README.md index 944101d..a4135a7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ ```sh $ git clone https://github.com/sinacloud/python-getting-started.git $ cd python-getting-started -$ python main.py +$ git checkout uwsgi +$ pip install -r requirements.txt +$ uwsgi --http 0.0.0.0:5050 --wsgi-file main.py ``` 现在,本示例应用已经跑在了你的 localhost:5050 端口上了。 diff --git a/main.py b/main.py index ac76dc0..e64b8e7 100644 --- a/main.py +++ b/main.py @@ -1,26 +1,3 @@ -import os -import tornado.httpserver -import tornado.ioloop -import tornado.options -import tornado.web -from tornado import gen -from tornado.httpclient import AsyncHTTPClient - -class MainHandler(tornado.web.RequestHandler): - - @gen.coroutine - def get(self): - http_client = AsyncHTTPClient() - response = yield http_client.fetch("http://www.sinacloud.com") - self.set_header('content-type', 'text/plain') - self.write('Hello, World! ' + str(response.body[:100])) - -application = tornado.web.Application([ - (r"/", MainHandler), -]) - -if __name__ == "__main__": - tornado.options.parse_command_line() - http_server = tornado.httpserver.HTTPServer(application) - http_server.listen(5050 or os.environ['PORT']) - tornado.ioloop.IOLoop.current().start() +def application(env, start_response): + start_response('200 OK', [('Content-Type','text/html')]) + return [b"Hello World"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index bd97c43..d470275 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ -tornado==4.2.1 -pillow - +uWSGI==2.0.18 diff --git a/runtime.txt b/runtime.txt index c47075b..651f607 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-2.7.9 +python-3.7.2 \ No newline at end of file diff --git a/sinacloud-packages.txt b/sinacloud-packages.txt new file mode 100644 index 0000000..c867c17 --- /dev/null +++ b/sinacloud-packages.txt @@ -0,0 +1 @@ +gcc-4.8 \ No newline at end of file