Questions tagged [python-asyncio]

Utilize this tag specifically for the asyncio Python package, designed to facilitate the creation of single-threaded concurrent code. With asynchronous I/O, event loop, coroutines, and tasks, the asyncio package has been available since Python 3.4.

python asyncio.gather incorporates user input into the final result

My function looks something like this: async def funcn(input: input_type) -> output_type: .... return output I am using asyncio.gather to call it in the following way: output = await asyncio.gather(*[funcn(input) for input in input_list]) The retu ...

Converting synchronous Python methods into asynchronous tasks

Have you heard of the Task.Run method in C# that accepts a delegate as a parameter and returns a task that can be awaited? Check it out here. Now, I'm wondering if there is a similar feature in Python's asyncio module. I have a synchronous block of code ...

Executing a for loop asynchronously on an AsyncGenerator

When working with an asynchronous generator, the expectation is to be able to iterate through it asynchronously. However, after running the code below, a synchronous for loop is produced instead: import asyncio async def time_consuming(t): print(f"G ...

Ways to confirm that the outcome was produced through asynchronous operations rather than from a pool

Required functions for testing (meaning I can only import them, not see the code): The file async_data.py import asyncio import socket import aiohttp async def get_json(client, uid): json_url = 'https://jsonplaceholder.typicode.com/todos/{uid}'.form ...

The asyncio add_signal_handler function is failing to capture the sigint and sigterm signals

I'm currently facing a challenge with debugging an issue in my asyncio project. My goal is to ensure it shuts down smoothly. import asyncio import signal async def clean_loop(signal, loop): print("something") tasks = [t for t in a ...

asyncio: Waiting for signal from external thread

Currently, I am in the process of developing a Python application that needs to interact with a machine to carry out time-consuming tasks. While the asyncio module is ideal for network operations, I am facing a challenge when it comes to accessing the seri ...

My Discord Python Bot Keeps Disrupting My Commands While Running Background Tasks

I've been developing a Python Discord bot that sends scheduled messages in a server at specific times every day, along with other functionalities. However, after implementing the scheduled messaging feature, the bot commands have stopped working - lea ...

Using asyncio, the function asyncio.sleep(5) will send each variable after a 5-second delay, rather than sending them one after another

Is there a way to optimize the asyncio.sleep() function? I am trying to send multiple commands using the method "async def send" with the parameter "command", and I want them to be sent one after the other. Currently, only one command is being sent and the ...

What is the best way to wait for an asynchronous call within a __get__ method of a descriptor?

I am looking to implement a lazyloadable property that loads data when first accessed through __get__(). However, I cannot set __get__() as async. Is there a way to wait for obj.load() to finish and then return the getter's result? class LazyLoadableP ...

Encountering a RuntimeError when attempting to run a JustPy web app on Jupyter

I've been attempting to run justpy web apps, like the one below, on Jupyter: import justpy as jp def hello_world(): wp = jp.WebPage() d = jp.Div(text='Hello world!') wp.add(d) return wp jp.justpy(hello_world) Unfortunately, I keep encoun ...

Mastering the art of efficiently capturing syntax errors using coroutines in Python

Currently, I am in the process of developing a Python script that runs two tasks simultaneously. Transitioning from JavaScript to Python's async/await coroutine features has presented some challenges for me as I have encountered unexpected behavior. Initi ...