Search code examples
pythonpython-3.xpython-3.6aiohttpfirebase-admin

aiohttp and firebase and firebase-admin - is it non blocking? python 3.6


python 3.6

Here is my firebase code that will check if user exists on firebase:

import firebase_admin
from firebase_admin import credentials
from firebase_admin import auth


cred = credentials.Certificate('wow.json')
default_app = firebase_admin.initialize_app(cred)

def getIsUser(email=None,uid=None):
        try:
            user = auth.get_user(uid)
            is_user = True
        except:
            is_user = False

    return is_user

Here is my aiohttp that calls the function:

async def jwt_route(request):
    data = await request.json()
    uid = data['uid']
    is_user = getIsUser(uid=uid)

app.router.add_post('/jwt', jwt_route)

My question is if the getIsUser(uid=uid) is blocking or not blocking. If blocking then how do I make it nonblocking?


Solution

  • Yes, getIsUser is a blocking call.

    Run it in thread pool: loop = asyncio.get_event_loop() is_user = loop.run_in_executor(None, getIsUser, uid)