endpoints
endpoints copied to clipboard
Asyncio interfaces
Now that python2 support has been dropped I think I will add asyncio support with the ASGI interface. After some tests, it looks like I can have the async and sync interfaces be the same, the sync will just extend the async interface and wrap all the methods, something like:
class AsyncFoo(object):
async def foo(self, ret_value, sleep=1):
print("async")
await asyncio.sleep(sleep)
print("foo")
return value
class SyncFoo(AsyncFoo):
def foo(self, *args, **kwargs):
return asyncio.run(super().foo(*args, **kwargs))
f = SyncFoo()
print(f.foo(6))
This works in my tests and so, hopefully, something similar to my tests will actually work when implemented so I can keep the interfaces the same and then it's just a choice on what to use.
Links I had open
- Python Asyncio docs
- Asyncio — Moving towards the asynchronous future of Python
- Django async docs
- Reddit Should I stick with asyncio, or return to gevent?
- asyncio_monkey
- SO Asyncio vs. Gevent
Search
- does python asyncio need monkey patching
- python async