Skip to content
Advertisement

Tag: python-asyncio

Error whenever I run code that requires aiohttp library

Whenever I run code which requires aiohttp, I get the error below: Examples of codes I’ve tried to run from https://docs.aiohttp.org/en/stable/ include: and I’ve tried several other examples but they all produce the same error. What could be causing this?. I’m using python 3.8.6 and the latest version of aiohttp Update: It seems the error is caused by importing aiohttp.

Opposite of asyncio.to_thread

How do I run asynchronous function in blocking style? I am not allowed to modify signature of my mock function f1() and can’t easy switch to async def and so can’t use await expression. I tried asyncio.get_running_loop().run_until_complete(t), but the hack does not work and I get the next error. Answer How do I run asynchronous function in blocking style? If

How to save UploadFile in FastAPI

I accept the file via POST. When I save it locally, I can read the content using file.read (), but the name via file.name incorrect(16) is displayed. When I try to find it by this name, I get an error. What might be the problem? My code: Answer Background UploadFile is just a wrapper around SpooledTemporaryFile, which can be accessed

Using an asynchronous function in __del__

I’d like to define what essentially is an asynchronous __del__ that closes a resource. Here’s an example. This works, printing destructing and closing as expected. However, if the resource is defined outside an asynchronous function, __del__ is called, but closing is never performed. No warning is raised here, but the prints reveal that closing was not done. The warning is

Write a CSV file asynchronously in Python

I am writing a CSV file with the following function: However, as there is no await allowed over writerows method, there are no rows being written into the CSV file. How to resolve this issue? Is there any workaround available? Thank you. Entire code can be found here. Answer In my opinion it’s better not to try to use the

Advertisement