Search code examples
azure-functionsazure-function-appazure-cosmosdb-gremlinapigremlinpython

not able to close connection python gremlin client


I have been using https://github.com/Azure-Samples/azure-cosmos-db-graph-python-getting-started project to work with cosmosdb-gremlin.

project work fine when i am running it as python function on windows.

now i am trying to convert this code into azure-function.

I am able to convert and run, faced couple of issues (tornado+python3.8 compatibility issue) (nest_asyncio). now i have resolved those errors but i am still getting following (attached screenshot)

this error comes, when i am trying to close the connection.

client.close().

so to avoid complete flow failure, i just wrapped it inside the try/catch. so now flow is going ahead and functionally i do not see any side effect.

but then i noticed something, the thread count keeps increasing with each run. I am not sure if this is because i am not closing error. I am afraid I may be accumulating orphan threads.

please suggest what can be done?

I am trying to modify code inside gremlin-python package, because then it may work locally, but i will have other issues while deploying it on azure.

i am using python 3.8.5

enter image description here


Solution

  • i was able to solve it by implementing 2 steps.

    1. changed axuze function by adding async.

      async def main(req: func.HttpRequest) -> func.HttpResponse:

    2. added these 2 lines top of the file...

      import nest_asyncio

      nest_asyncio.apply()

    3. downgraded tornado by adding following entry in requirement.txt

    tornado==4.5.3