GeezerVison is showing github.com — asyncio support · Issue #3103 · googleapis/google-cloud-python
DescriptionI want to use google-cloud-python in a Sanic web service, however I'm having to use run_in_executor() to use this library without stalling the eventloop.
This is much less efficient than an Asyncio native client. Reacted by Sacha, Alex, Jack Crawford, Thomas Cellerier, Joshua Hendinata, Clark Zinzow, Sami, af-dk, Denis, Marco and 21 more Activitygraingert commented on Mar 6, 2017 @jonparrott it would be possible to support python 2.x and python 3.x with various event loops from the same source by using a custom deferred, future or IOAction implementation. theacodes commented on Mar 6, 2017 This might be possible once we exorcise httplib2 from this project. @lukesneeringer lukesneeringer commented on Mar 6, 2017 That sounds right to me (and that has moved up in priority slightly).
Tagging #1998 for reference. graingert commented on Mar 6, 2017 the core code would use Action composition:
return get_url(xys).map(process_request).flat_map(make_another_request)
Then there could be various, pluggable http transport implementations, that would take an Action instance and return a Future from various event systems (asyncio, twisted), or even use blocking IO. graingert commented on Mar 8, 2017 import asyncio
import functools
class AsyncIOAction(object):
def __init__(self, fn):
this.exec = fn
def map(self, fn):
@functools.wraps(fn)
async def exec():
value = await self.exec()
return fn(value)
return AsyncIOAction(exec)
def flat_map(self, fn):
@functools.wraps(fn)
async def exec():
value = await self.exec()
return await fn(value).exec()
return AsyncIOAction(exec)
@classmethod
def all(items):
async def exec():
return await asyncio.wait([x.exec() for x in items])
return AsyncIOAction(exec)
def aiohttp_action(request):
async def exec():
return await aiohttp.request(**request)
return AsyncIOAction(exec)
# blocking.py
import functools
class BlockingIOAction(object):
def __init__(self, fn):
this.exec = fn
def map(self, fn):
@functools.wraps(self, fn)
def exec():
value = self.exec()
return fn(value)
return BlockingIOAction(exec)
def flat_map(self, fn):
@functools.wraps(fn)
def exec():
value = self.exec()
return fn(value).exec()
return BlockingIOAction(exec)
@classmethod
def all(items):
def exec():
return [x.exec() for x in items]
return BlockingIOAction(exec)
def requests_action(request): # or httplib2 etc.
def exec():
requests.request(**request)
return BlockingIOAction(exec)
# twisted.py
class TwistedIOAction(object):
...
Should be pretty easy with twisted deferred too. Idea being, calling code would choose an IO type, configure the google cloud platform library appropriately, call a method on some API endpoint and then be able to call .exec() on the returned action. The calling code would then be able to receive the value, await and receive the value, or yield it in twisted inline callbacks. graingert commented on Mar 8, 2017 graingert commented on Mar 8, 2017 inside google code platform:
def some_api_method(IOAction, ham, spam):
@IOAction.inline_callbacks
def _some_api_method():
v = yield some_other_method(IOAction, ham)
v2 = yield another_method(IOAction, spam, v)
Return(v + v2)
return _some_api_method()
In some calling code:
async def async_caller():
await some_api_method(AsyncIOAction, ham="ham", spam="spam").exec()
def blocking_caller():
some_api_method(BlockingIOAction, ham="ham", spam="spam").exec()graingert commented on Jul 24, 2017 theacodes commented on Jul 24, 2017 @graingert oh that's super interesting. However, this seems to re-enforce the fact that we can't really support this without breaking our public interface and without seriously re-thinking all of our internals. We'd have to start from scratch with this in mind. :/ graingert commented on Jul 24, 2017 theacodes commented on Jul 24, 2017 inlinecallbacks would help, but this is an enormous undertaking and a lot of our code that deals with IO is non-trivial (resumable-media).
I'm open to doing this, but from my perspective it seems like the tooling isn't quite ready and it would take an enormous amount of engineering effort to get all of our plumbing ready- plus, we have a consider how gRPC plays into all this. dhermes commented on Jul 24, 2017 FWIW, resumable-media would be the easiest thing of all to add support for because the actual I/O is "isolated" (I took the sans-I/O approach when writing it) vladyslav2 commented on Jul 31, 2018 @theacodes why do you believe supporting python 3 will be so significant big task?
Are you willing to accept help from a community? I just check iot-core (stuff that i'm interested) and most of calls based on the paho.mqtt.python library which does support asyncio.
So, i'm expecting I can port google-cloud-python/iot in few days since you have tests coverage theacodes commented on Jul 31, 2018 It's not that supporting python 3 is a significant task (we *do* support
Python 3 after all), it's that maintaining 2 separate, divergent codebases
for 40+ libraries isn't feasible. It's much more realistic for us to wait
until we can remove 2.7 support.
One of the reasons these libraries are open so is precisely to empower
users to fork and extend as much as they want. So you're welcome to do so,
just note that any support for that will be best-effort.
…syenchuk commented on Dec 19, 2018 Please drop support for 2.7 now and add asyncio support :)
Blocking networking calls is such a slow, has-been thing… Reacted by Vladyslav Tarasenko, Jonathan Striebel, Alex, Britton Winterrose, Moe-Kite, Maz, Yury Zhuravlev, Santiago Valdarrama, Derek Hao Hu, QaisarTanvir and 30 more rubik commented on Aug 7, 2019 What is the status of this issue? Will it be fixed in the near future? tseaver commented on Aug 7, 2019 @rubik Dropping 2.7 support is scheduled for Q1 2020. Adding asyncio support will be a major effort, but the relative priority for it isn't set, AFAIK. Reacted by Michele Lacchia, af-dk, Denis, Gary Oberbrunner, Yixi Zhang, Malar Kannan, min(max), Adam Eury, Chanhyeong Lee, Jacob Tomlinson and 1 more kamyar commented on Jun 3, 2020 Is there any development on this front?
Also can you please reopen this issue as it is mentioned as a blocker for firebase/firebase-admin-python#104 ?
We have been using firestore and lack of async is a very big downside of firestore.
If async supported is not planned for google services, It would be nice if we know beforehand so we can plan our migration to services that support it. Lack of this feature is causing us both money and product quality tbh. software-dov commented on Jun 3, 2020 API core is adding asyncio support right now (see here for details), but it's tough to say how long before client libraries providing asynchronous interfaces will be available. Reacted by Kamyar, Chanhyeong Lee, Akarsh and mrkiril94 Reacted by Kamyar, Luke Holroyd, Chanhyeong Lee and Sam Millar ntoshev commented on Mar 17, 2021 Reacted by Peter Whidden and Akarsh NoamNol commented on Aug 8, 2021 Reacted by Andres and Chris Walker adriangb commented on Apr 17, 2022 FWIW one workaround I've been using is generating presigned URLs for myself and then using them with httpx. But that compounds with other issues, namely #922. Python 2 has been EOL for 2 years now. zagfai commented on Jun 9, 2022 karthikv2k commented on Dec 4, 2024 How is a one of top 3 cloud providers not supporting async python SDK! this is a big miss. Reacted by Mykola Morozov and Panwen Wang
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|