Created
December 4, 2014 07:53
Revisions
-
1st created this gist
Dec 4, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ """ Demonstration how to execute Python code parallel with `yield` keyword. Need Python 3.3 or above to use "return" in generator function. This experiment is a step to implement Node.JS-like parallelism into Python web framework WebPages <https://github.com/webpages/webpages> """ def query_db(): return "result from database" def operation_with_file(filename): return "file content" def render(template, data): return template.format(data) def request_handler(): filename = "hello.html" template = yield operation_with_file(filename) data = yield query_db() return render(template, data) for result in request_handler(): pass