You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The application should connect to the database without errors when running in async mode.
Actual Behavior
The application throws the error mentioned above and fails to connect.
Steps to Reproduce
Create a Python Azure Functions app structured with Blueprints.
Add asyncio logic and attempt to establish an async connection with Psycopg.
Run the app on Windows.
Relevant code being tried
``
import asyncio
import azure.functions as func
import datetime
import json
import logging
from psycopg_pool import AsyncConnectionPool
app=func.FunctionApp()
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
@app.route(route="test")
async def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
# Database connection parameters
conn_info = "dbname=test user=testpassword=123 host=localhost port=5432"
try:
pool = AsyncConnectionPool(conninfo=conn_info ) # Connect to the database
async with pool.connection() as conn:
async with conn.cursor() as cur: # Execute the query
await cur.execute("SELECT * FROM test LIMIT 1;")
row = await cur.fetchone() # Process the result if row:
return func.HttpResponse(f"Row: {row}", status_code=200)
else:
return func.HttpResponse("No rows found", status_code=404)
except Exception as e:
logging.error(f"Error: {e}")
return func.HttpResponse(f"Error: {e}", status_code=500)
Relevant log output
error connecting in'pool-1': Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())'
I am facing an issue with my Python Azure Functions application (v2), which is structured using Blueprints. When I add asyncio to the application and try to run it on Windows, it throws the error mentioned above.
I have tried the solution mentioned in various pages where the event loop policy is explicitly set as shown below:
Expected Behavior
The application should connect to the database without errors when running in async mode.
Actual Behavior
The application throws the error mentioned above and fails to connect.
Steps to Reproduce
Relevant code being tried
``
Relevant log output
requirements.txt file
Where are you facing this problem?
Local - Core Tools
Function app name
No response
Additional Information
I am facing an issue with my Python Azure Functions application (v2), which is structured using Blueprints. When I add asyncio to the application and try to run it on Windows, it throws the error mentioned above.
I have tried the solution mentioned in various pages where the event loop policy is explicitly set as shown below:
I have tried adding this in function_app.py but the issue persists. I am using python 3.11.
I would appreciate any guidance on resolving this issue or insights into potential misconfigurations.
The text was updated successfully, but these errors were encountered: