async-await

Proper way to cancel remaining trio nursery tasks inside fastAPI websocket?

Proper way to cancel remaining trio nursery tasks inside fastAPI websocket? Question: I’m still quite new to websockets and I’ve been given a problem I’m having a hard time solving. I need to build a websocket endpoint with FastAPI in which a group of tasks are run asynchronously (to do so I went with trio) …

Total answers: 1

how to access relationships with async sqlalchemy?

how to access relationships with async sqlalchemy? Question: import asyncio from sqlalchemy import Column from sqlalchemy import DateTime from sqlalchemy import ForeignKey from sqlalchemy import func from sqlalchemy import Integer from sqlalchemy import String from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy.future import select from sqlalchemy.orm import declarative_base from sqlalchemy.orm import relationship from …

Total answers: 3

django async if else use a thread or sync_to_async

django async if else use a thread or sync_to_async Question: I don’t know where the error is. I am using Django ORM asynchronously. @database_sync_to_async def filter_data(**kwargs): return FinishAnimateModel.objects.filter(**kwargs) async def receive(self, text_data=None, bytes_data=None): … if data[‘msg’]: print(‘in’) model = await DB.Myself.filter_data(name__contains=”) print(‘ok’) else: print(‘else’) model = await DB.Myself.filter_data(name__contains=”) print(model, ‘model’) In if log in ok …

Total answers: 1

Have you ever get RuntimeError: await wasn't used with future?

Have you ever get RuntimeError: await wasn't used with future? Question: trying to extract data from a website by using asyncio and aiohttp, and AWAIT problem occur in for loop function. here my script : async def get_page(session,x): async with session.get(f’https://disclosure.bursamalaysia.com/FileAccess/viewHtml?e={x}’) as r: return await r.text() async def get_all(session, urls): tasks =[] sem = asyncio.Semaphore(1) …

Total answers: 2

Difference between async await in python vs JavaScript

Difference between async await in python vs JavaScript Question: Note: this is not about multi threading or multi processing. This question is regarding a single process and single thread. Python async.io and JavaScript async both are single thread concepts. In python, async.io, we can use async await keywords to create a function so that when …

Total answers: 3

Executing an awaitable / async function in Python RQ

Executing an awaitable / async function in Python RQ Question: My jobs are all a series of requests that need to be made per object. Ie, its a User with several data points (potentially hundreds) that need to be added to that user with requests. I had originally written those requests to run synchronously but …

Total answers: 3

What are the differences between Python Playwright sync vs. async APIs?

What are the differences between Python Playwright sync vs. async APIs? Question: I’ve started learning playwright-python and the package playwright has the two submodules async_api and sync_api. However I could not find any deeper description or discussion on their respective benefits and drawbacks. From their names I assume that the synchronous API calls are blocking …

Total answers: 1

How can I send an HTTP request from my FastAPI app to another site (API)?

How can I send an HTTP request from my FastAPI app to another site (API)? Question: I am trying to send 100 requests at a time to a server http://httpbin.org/uuid using the following code snippet from fastapi import FastAPI from time import sleep from time import time import requests import asyncio app = FastAPI() URL= …

Total answers: 2

How to stop an Azure Event Hub Consumer Client in Python

How to stop an Azure Event Hub Consumer Client in Python Question: I am running into some trouble with Azure Event Bub with Python. Below is my strater code for connection (Taken from microsoft docs) import asyncio from azure.eventhub.aio import EventHubConsumerClient from azure.eventhub.extensions.checkpointstoreblobaio import BlobCheckpointStore async def on_event(partition_context, event): # Print the event data. print("Received …

Total answers: 2