Created
December 4, 2014 07:53
-
-
Save 1st/c22d676ec59703ce23e9 to your computer and use it in GitHub Desktop.
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
""" | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems 11 years ago I thought about async abilities in Python :-)