Falcon 3.0 Roadmap
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
#!/usr/bin/python3 | |
import sys | |
import asyncio | |
import greenlet | |
class AsyncIoGreenlet(greenlet.greenlet): | |
def __init__(self, driver, fn): | |
greenlet.greenlet.__init__(self, fn, driver) | |
self.driver = driver |
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
"""This program is exactly the same as that of | |
https://gist.github.com/zzzeek/33943060f7a08cf9e82bf8df1f0f75de , | |
with the exception that the add_and_select_data function is written in | |
synchronous style. | |
UPDATED!! now includes refinements by @snaury and @Caselit . SIMPLER | |
AND FASTER!! |
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
"""Proof of concept of an adapter that will wrap a blocking IO library in | |
greenlets, so that it can be invoked by asyncio code and itself make calls out | |
to an asyncio database library. | |
hint: any Python ORM or database abstraction tool written against the DBAPI | |
could in theory allow asyncio round trips to a pure async DB driver like | |
asyncpg. | |
The approach here seems too simple to be true and I did not expect it to | |
collapse down to something this minimal, so it is very possible I am totally |
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 falcon | |
class TestResponse(): | |
def on_get(self, req, resp): | |
resp.body = "Success" | |
resp.content_type = falcon.MEDIA_TEXT | |
application = falcon.API() | |
# http://localhost/item/19/01/01/Item-190101-59559ee7-e661-43c8-9da1-0ab83b9e0d8e.json | |
application.add_route("/item/{y:int}/{m:int}/{d:int}/Item-{yymmdd:int}-{item_id:uuid}.json", TestResponse()) |
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
class ChunkyBacon(): | |
def __init__(self, baconator): | |
self._baconator = baconator | |
async def on_get(self, req, resp, bacon_id=None): | |
# Use JSON serializer to send it back in one chunk | |
resp.media = await self._baconator.get_bacon(bacon_id) | |
resp.set_header('X-Powered-By', 'Bacon') |
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 os | |
def on_starting(server): | |
""" | |
Attach a set of IDs that can be temporarily re-used. | |
Used on reloads when each worker exists twice. | |
""" | |
server._worker_id_overload = set() |