python-asyncio Questions

2

Solved

I can't seem to wrap my head around the issue here. I'm writing tests for my Channel Consumers following the description in the docs. I'd normally use the Django default unittest but since Channels...
Selfeffacing asked 15/1, 2019 at 3:58

6

Solved

In asynchronous JavaScript, it is easy to run tasks in parallel and wait for all of them to complete using Promise.all: async function bar(i) { console.log('started', i); await delay(1000); con...
Plumbism asked 20/12, 2015 at 2:7

0

I needed to use cache in a web application built in Python. Since I couldn’t directly use lru_cache in a coroutine, I built a simple decorator that would allow me to use it: from asyncio import Loc...
Foushee asked 11/2 at 19:50

12

Solved

I found that in Python 3.4, there are few different libraries for multiprocessing/threading: multiprocessing vs threading vs asyncio. But I don't know which one to use or is the "recommended o...

1

Solved

Using FastAPI : 0.101.1 I run this test_read_aynsc and it pass. # app.py from fastapi import FastAPI app = FastAPI() app.get("/") def read_root(): return {"Hello": "Worl...

3

Solved

I cannot wrap my head around type hinting a Coroutine. As far as I understand, when we declare a function like so: async def some_function(arg1: int, arg2: str) -> list: ... we effectively dec...
Hittel asked 4/8, 2022 at 18:17

3

Solved

When I go to the asyncio page, the first example is a hello world program. When I run it on python 3.73, I can't see any different from the normal one. can anyone tell me the difference and give a ...
Tidwell asked 24/6, 2019 at 4:14

3

Solved

UPDATED QUESTION FOR CLARITY: suppose I have 2 processing generator functions: def gen1(): # just for examples, yield 1 # yields actually carry yield 2 # different computation weight yield 3 #...

3

Solved

My server exposes an API for a resource-intensive rendering work. The job it does involves a GPU and as such the server can handle only a single request at a time. Client should submit a job and re...
Aviles asked 19/1 at 18:0

3

The documentation for asyncio gives two examples for how to print "Hello World" every two seconds: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio-hello-world-callback https://docs...
Princely asked 9/10, 2014 at 5:3

15

Solved

How can I define a class with await in the constructor or class body? For example what I want: import asyncio # some code class Foo(object): async def __init__(self, settings): self.setting...
Subcontinent asked 14/10, 2015 at 14:36

9

Solved

I'd like to call exec in an async function and do something like the following code (which is not valid): import asyncio async def f(): await exec('x = 1\n' 'await asyncio.sleep(x)') More prec...
Abduction asked 1/7, 2017 at 9:1

4

I just discovered new features of Python 3.11 like ExceptionGroup and TaskGroup and I'm confused with the following TaskGroup behavior: if one or more tasks inside the group fails then all other no...
Aphaeresis asked 26/1, 2023 at 19:27

3

Solved

I am using sqlalchemy + asyncpg, and 'selectin' eager loading. I have Person items that have one-to-many relationships with Friends. I insert a Person into my database, with no related Friend entri...
Pharisaism asked 15/10, 2021 at 17:5

2

Solved

When testing the following code @pytest.mark.asynico async def test_handle_DATA(mocker): handle_mock = mocker.MagicMock() envelope_mock = mocker.MagicMock(mail_from="Test@From", rcpt_to...
Refractor asked 28/4, 2019 at 18:17

2

Solved

We all know that using asyncio substantially improves the performance of a socket server, and obviously things get even more awesome if we could take advantage of all cores in our cpu (maybe via mu...
Tyndall asked 1/6, 2019 at 18:49

2

I am trying to asynchronously send some Multipart-Encoded Form Data as a post request, mainly a file and two other fields. Before trying to use asyncio I was doing the process synchronously with r...
Arteriovenous asked 14/8, 2019 at 22:8

2

Solved

I'm using the websockets module, but it doesn't support connecting though my corporate proxy for a client connection: >>> import asyncio, websockets >>> async def connect(uri): ....
Session asked 10/11, 2017 at 14:53

2

Solved

I want to use both ThreadPoolExecutor from concurrent.futures and async functions. My program repeatedly submits a function with different input values to a thread pool. The final sequence of tas...
Pennyroyal asked 19/2, 2019 at 4:37

3

Solved

I think the example below is a really common use case: create a connection to a database once, pass this connection around to test which insert data pass the connection to a test which verifies ...
Bangs asked 21/5, 2019 at 10:47

2

Solved

Is it possible to use Python's asyncio on Google Cloud Functions? async def handle_someting(): # do something some = await aiofunc() # Do I need the code below? loop = asyncio.get_event_loop() ...
Shawndashawnee asked 11/10, 2018 at 8:51

6

Solved

I have a controller action in aiohttp application. async def handler_message(request): try: content = await request.json() perform_message(x,y,z) except (RuntimeError): print("error in perfo...
Purveyance asked 19/6, 2017 at 12:32

4

Solved

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 Str...
Ascospore asked 25/11, 2021 at 1:35

2

Solved

Why do we need the asyncio.coroutine decorator? What functionality does it provide? For example: # import asyncio # @asyncio.coroutine def gen(): value = yield("Started") print(value) a = gen(...
Midwife asked 5/11, 2017 at 10:57

2

Solved

I work with the OpenAI API. I have extracted slides text from a PowerPoint presentation, and written a prompt for each slide. Now, I want to make asynchronous API calls, so that all the slides are ...
Hydromedusa asked 22/5, 2023 at 10:23

© 2022 - 2024 — McMap. All rights reserved.