Skip to main content

All Questions

1 vote
1 answer
102 views

how to call async function for timer in python

I would like two parameters: freq1 and freq2 to swap at a interval freq_change_interval - this is in a existing python project which already uses async in some methods, but the existing main(): method ...
Radika Moonesinghe's user avatar
0 votes
0 answers
49 views

Asyncio async funcitons hangs with asyncio.gather. (the code works without asyncio.gather)

The following code runs well if did not put the async functions inside a asyncio.gather and let them run one after another (with awaits). But when I add them to an asyncio.gather, it prints "...
Tharusha Jayasooriya's user avatar
0 votes
0 answers
32 views

The set_result() of Future doesn't end the await after the loop of create_task()

I write a Python program involving a loop of create_task() that calls async functions. In each task, it waits for another thread to set the result for a Future object. async def run(self) -> int: ...
Lesterth's user avatar
0 votes
2 answers
95 views

Creating a stoppable background task in Python

I want to run some function in the background, but be able to shut it down at will. I tried a bunch of solutions, the most obvious of which is asyncio tasks: # Data source DataSource = Generator[int, ...
Docom's user avatar
  • 25
1 vote
3 answers
101 views

Why the async-code is printing these things and in this order?

I'm trying to understand asynchronous programming in Python, and I've stumbled to see the output of the code import asyncio async def my_coroutine(): print("Coroutine started") ...
ankit's user avatar
  • 13
1 vote
1 answer
64 views

Python async performance doubts

I'm running an websocket application through Django Channels and with Python 3.12. I have a ping mechanism to check if my users are still connected to my application where at a fixed time interval the ...
Pedro Silva's user avatar
0 votes
0 answers
44 views

Asyncio server and client

Here is a demo implements the communication between client and server. import asyncio import json import time reader = None writer = None ip = '127.0.0.1' port = 8889 async def handle_input(): ...
hhhhh's user avatar
  • 1
0 votes
1 answer
44 views

Any difference between await asyncio.Task and asyncio.Task.result()?

After the task already completed, is there any difference between await asyncio.Task and asyncio.Task.result()? The only difference in the following code is how I read the value in task. import ...
pegasus's user avatar
  • 85
0 votes
1 answer
65 views

Python async sleep question ordering of execution

Hello I have a quesiton while I'm working through some tutorial on asyncio as given below: import asyncio async def task_coroutine(): print('start executing task') await asyncio.sleep(1.0) ...
charlielao's user avatar
0 votes
0 answers
148 views

Stream response in Flask with AsyncGenerator

I would need to stream data to the user via an endpoint through a function that returns an AsyncGenerator The idea is as follows: message_route = Blueprint('message_route', __name__, template_folder='...
Lorenzo Vaccher's user avatar
0 votes
1 answer
76 views

How to combine asynchronous I/O and CPU-bound tasks efficiently in Python?

I'm working on a Python project where I need to handle both asynchronous I/O tasks (like reading from a file or making API requests) and CPU-bound tasks (like data processing or calculations). I’m ...
Meeooowwww's user avatar
0 votes
0 answers
20 views

How to close an asynchronous task that hosts a simple synchronous HTTPServer?

I have the following Python code snippet: import asyncio import http.server import socketserver class StoppableHTTPServer(socketserver.TCPServer): allow_reuse_address = True def stop(self): ...
LuckyCoder3607's user avatar
0 votes
0 answers
81 views

Python 3.10+: call async function within a property in a way that does not produce errors if that property is accessed in an async function

I have built a library that includes an ORM with the following use pattern: class Model(SqlModel): columns = ('id', 'details', 'parent_id') parent: RelatedModel Model.parent = belongs_to(...
Jonathan Voss's user avatar
0 votes
1 answer
182 views

Correct usage of async session on pytest

Given below implementation, I try to test using an asynchronous session. My attempt goes in the following way: models.py from sqlalchemy.engine import Connection from sqlalchemy.ext.asyncio import ...
Bruno Lobo's user avatar
0 votes
1 answer
110 views

How to read async stream from non-async method? [duplicate]

I use FastAPI to create the app. One of features is upload of files with PUT request. Fast API supports uploading files with POST requests (multipart form). But I need the PUT request where a file is ...
Roman Gelembjuk's user avatar

15 30 50 per page
1
2 3 4 5
39