python-asyncio

How to handle "coroutine never awaited" as an exception?

How to handle "coroutine never awaited" as an exception? Question: There are many answers about how to ignore or fix this, but what I need is a solution that would handle these, because we have a huge project and something like this is bound to happen, but it’s silent and therefore goes unnoticed for some …

Total answers: 1

Why gather() is faster than for loop in asyncio?

Why gather() is faster than for loop in asyncio? Question: Why first code is slower than second? (Only the definition of ret has changed) This is a fragment of my code and in the full program, about fifty links are fed into the main function. async def get(url, session): try: async with session.get(url) as response: …

Total answers: 1

How to debug blocking in a python async function

How to debug blocking in a python async function Question: I have zero knowledge of asynchronous python other than several hours of searching stackoverflow posts, and am struggling to figure out what is, occasionally, causing the below error: Triggerer’s async thread was blocked for 0.26 seconds, likely by a badly-written trigger. Set PYTHONASYNCIODEBUG=1 to get …

Total answers: 1

The explicit passing of coroutine objects to asyncio.wait() is deprecated

The explicit passing of coroutine objects to asyncio.wait() is deprecated Question: From this github link: https://github.com/pyxll/pyxll-examples/blob/master/bitmex/bitmex.py When I run this code, I get the message saying the explicit passing of coroutine objects to asyncio.wait() is deprecated. I’ve pinpointed this to line 71: await asyncio.wait(tasks), but can’t figure out how to resolve the issue. Code below …

Total answers: 1

Can I download a large file in the background using aiohttp?

Can I download a large file in the background using aiohttp? Question: I’d like to download a series of large (~200MB) files, and use the time while they’re downloading to do some CPU intensive processing. I’m investigating asyncio and aiohttp. My understanding is I can use them to start a large download and then do …

Total answers: 2

Why this asyncio code doesn't run concurrent?

Why this asyncio code doesn't run concurrent? Question: Hello I am trying to write a script to process pdf files with asyncio concurrent in order to do this I have the following code: import click import asyncio from pdf2image import convert_from_path from functools import wraps def coro(f): @wraps(f) def wrapper(*args, **kwargs): return asyncio.run(f(*args, **kwargs)) return …

Total answers: 1

How do you make faster A.P.I calls using multithreading without using requests in Python?

How do you make faster A.P.I calls using multithreading without using requests in Python? Question: I’m trying to receive historical stock data for every company in the S&P 500. The problem is that it is taking a really longtime to get the data. from ApiStuff import ApiStuff import fundamentalanalysis as fa import pickle tickers = …

Total answers: 2

asyncio TaskGroup throwing TypeError when returning lists

asyncio TaskGroup throwing TypeError when returning lists Question: I am trying to use the new TaskGroup object in Python 3.11 to return lists, and I am struggling to find the correct syntax. There isn’t much example code out there yet for this new feature, so I figured I’d ask. import asyncio async def squares(nums): return …

Total answers: 1

Extract stdout from long-running process

Extract stdout from long-running process Question: Disclaimer: I have seen many similar questions, but either they do not use asyncio, or they don’t seem to do exactly what I do. I am trying to get the output of a long-running command (it’s actually a server that logs out to stdout) with the following: proc = …

Total answers: 1