- By Edmond Lau
- Highly Recommended 👍
- http://www.theeffectiveengineer.com/
- They are the people who get things done. Effective Engineers produce results.
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "os" | |
| "os/signal" |
Asynchronous programming can be tricky for beginners, therefore I think it's useful to iron some basic concepts to avoid common pitfalls.
For an explanation about generic asynchronous programming, I recommend you one of the [many][2] [resources][3] [online][4].
I will focus on solely on asynchronous programming in [Tornado][1]. From Tornado's homepage:
| from flask import Flask | |
| app = Flask(__name__) | |
| @app.route("/") | |
| def hello(): | |
| return "Hello bar!" | |
| if __name__ == "__main__": | |
| app.run(host='0.0.0.0',port=8000) |
| from flask import Flask | |
| app = Flask(__name__) | |
| @app.route("/") | |
| def hello(): | |
| return "Hello foo!" | |
| if __name__ == "__main__": | |
| app.run(host='0.0.0.0') |
| --type-set=coffee=.coffee | |
| --type-set=haml=.haml | |
| --type-set=sass=.sass | |
| --type-set=minifiedjs=.min.js | |
| --nocss | |
| --nominifiedjs | |
| --ignore-dir=coverage | |
| --ignore-dir=dragonfly | |
| --ignore-dir=javascripts/lib |
Wensheng Wang, 10/1/11
Source: http://blog.wensheng.org/2011/10/performance-of-flask-tornado-gevent-and.html
When choosing a web framework, I pretty much have eyes set on Tornado. But I heard good things about Flask and Gevent. So I tested the performance of each and combinations of the three. I chose something just a little more advanced than a "Hello World" program to write - one that use templates. Here are the codes:
| # Copyright (c) 2010, Philip Plante of EndlessPaths.com | |
| # | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| # of this software and associated documentation files (the "Software"), to deal | |
| # in the Software without restriction, including without limitation the rights | |
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| # copies of the Software, and to permit persons to whom the Software is | |
| # furnished to do so, subject to the following conditions: | |
| # | |
| # The above copyright notice and this permission notice shall be included in |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # | |
| # Copyright 2012 Ethan Zhang<http://github.com/Ethan-Zhang> | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | |
| # not use this file except in compliance with the License. You may obtain | |
| # a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 |