Created
May 30, 2012 14:18
-
-
Save gennad/2836618 to your computer and use it in GitHub Desktop.
Python task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from wsgiref.util import setup_testing_defaults | |
| from wsgiref.simple_server import make_server | |
| def timeit(func): | |
| def wrapper(*a, **k): | |
| t1 = time.time() | |
| it = iter(func(*a, **k)) | |
| try: | |
| while True: | |
| yield next(it) | |
| except StopIteration: | |
| pass # Or here | |
| print time.time() - t1 # Only successful finish | |
| return wrapper | |
| @timeit | |
| def app(environ, start_response): | |
| start_response("200 OK", []) | |
| for _ in xrange(1000): | |
| yield "12345" * 10 * 1024 * 1024 # 52 428 800 bytes * 1000 about 50 GB | |
| httpd = make_server('', 8080, app) | |
| print "Serving on port 8080..." | |
| httpd.serve_forever() |
Author
Да-да, это именно оно. Просто, надёжно и отвечает всем требованиям. Если есть требование писать время всегда, независимо от ошибок – весь for оборачивается в try/finally. Очень рад.
Author
=) спасибо
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Нет, мне наоборот интересно :)
Простое решение... Хм, может что-то вроде этого:
Если это не то, скажите, какой правильный ответ )