asynchronous

Asyncio getting different outputs

Asyncio getting different outputs Question: In the first example I am getting output I expect here to be, but I can’t say same about second example. Technically, in both example I have 3 tasks (Just in second example, I am scheduling 2 coros execution from main coro) isn’t it ? In second example, why Event …

Total answers: 1

How to pass body into aiohttp get request?

How to pass body into aiohttp get request? Question: How do I pass a body into aiohttp’s get requests? The code I have below is what I want to run asynchronously but im not able to get the same response – using requests request_accounts = requests.get( "{hostname}/audit/events".format( hostname=settings.RM_BASE_URL ), json={ "type": { "id": 2 }, …

Total answers: 1

Unclosed socket due to spawn child processes using multiprocessing

Unclosed socket due to spawn child processes using multiprocessing Question: I don’t really understand what’s going on with http requests. When I started child processes and uvicorn timeout_keep_alive timed out, I tried hitting "stop" in the browser and got infinite loading and no HTTP connection log. But if I try to click other buttons or …

Total answers: 2

Running trivial async code from sync in Python

Running trivial async code from sync in Python Question: I’m writing some parser code to be used with async IO functions (using Trio). The parser gets passed an object that exports an async read() method, and calls that method in the course of parsing. Ordinarily, this code will be run using data straight off the …

Total answers: 2

python async function proper syntax

python async function proper syntax Question: I’m trying to correct my async func to work with this script: import asyncio import platform import aiohttp if platform.system() == ‘Windows’: asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) url = ‘https://services.rappi.com.br/api/ms/web-proxy/dynamic-list/cpgs/’ req_headers = {‘authority’: ‘services.rappi.com.br’, ‘accept’: ‘application/json’, ‘authorization’: ‘Bearer ft.gAAAAABjMbGKkc2fkTMa2M2EKuBrCM1Z1vU5Ww1Fw03CjpJEb9UF1DO1TAjwpAD0H0NIImuMjWFcOkUURseLzJIi0DNSOr-oRWcZWgcnHLm2Ed6rDLvxQ2ikdGLtyVXZRqgGHWOMlBPVSKjYLb6NMZmAeHhAsGNjiQ3vP5VEdb_ULA9S5Lpo8H7-ElhKufmlVqQ6CrDyTUsyQeZ3IzbNCbN8MBLFhgRxVMZSwyl640YXF9ZvQUI1sibP-Ko86xrin_2EXEmAdEk7aSl9u0ezlmnBL6Wk8a7CwSJUEUAwAjrNdJTLSodjQaiVVx7TZ0rQEkzPgceaH7wtpmvl–6txmRDnBu4g0na3Km19K1LNzs0fz7-_Go8Qlg=’, ‘deviceid’: ‘957933bd-cdc4-4876-ad00-bc00a1d55c29’, ‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 …

Total answers: 1

Killing child process/task without killing main in Python using Pool Executor

Killing child process/task without killing main in Python using Pool Executor Question: I am trying to implement a method to force stop the child that have been started with ThreadPoolExecutor / ProcessPoolExecutor. I would like a cross platform implementation (Windows and Linux). When the signal is triggered from main, the main process exits and I …

Total answers: 2

How to avoid "too many requests" error with aiohttp

How to avoid "too many requests" error with aiohttp Question: Here’s a snippet of my parser code. It does 120 requests asynchronously. However, every response returns 429 "too many requests" error. How do I make it "slower", so the api won’t reject me? def get_tasks(self, session): tasks = [] for url in self.list_of_urls: tasks.append(asyncio.create_task(session.get(url, ssl=False))) …

Total answers: 1

Error AttributeError: module 'aiohttp' has no attribute 'ClientSession'

Error AttributeError: module 'aiohttp' has no attribute 'ClientSession' Question: Error AttributeError: module ‘aiohttp’ has no attribute ‘ClientSession’, But ClientSession exists in module, idk how to solve it. i tried everthing someone help import aiohttp import asyncio import json import time async def get_page (session,url): async with session.get(url) as r: return await r.text() async def get_all(session,urls) …

Total answers: 1

run functions in paralel Python

run functions in paralel Python Question: I have a stream and i have a function I want to run, when i receive the message on this stream async def some_func(): asyncio.sleep(5) print("hello world") client = create_client(‘wax.dfuse.eosnation.io:9000’) stream = client.Execute(Request(query = OPERATION_EOS)) for rawRequest in stream: async.gather(some_func()) If there are 2 or more messages at the …

Total answers: 3