async-await

How to integrate asyncronous python code into synchronous function?

How to integrate asyncronous python code into synchronous function? Question: I have an external library that uses requests module to perform http requests. I need to use the library asynchronously without using many threads (it would be the last choice if nothing else works). And I can’t change its source code either. It would be …

Total answers: 3

Asyncio getting different outputs

Asyncio getting different outputs Question: In the first example I am getting output I expect here to be, but I can’t say same about second example. Technically, in both example I have 3 tasks (Just in second example, I am scheduling 2 coros execution from main coro) isn’t it ? In second example, why Event …

Total answers: 1

python async function proper syntax

python async function proper syntax Question: I’m trying to correct my async func to work with this script: import asyncio import platform import aiohttp if platform.system() == ‘Windows’: asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) url = ‘https://services.rappi.com.br/api/ms/web-proxy/dynamic-list/cpgs/’ req_headers = {‘authority’: ‘services.rappi.com.br’, ‘accept’: ‘application/json’, ‘authorization’: ‘Bearer ft.gAAAAABjMbGKkc2fkTMa2M2EKuBrCM1Z1vU5Ww1Fw03CjpJEb9UF1DO1TAjwpAD0H0NIImuMjWFcOkUURseLzJIi0DNSOr-oRWcZWgcnHLm2Ed6rDLvxQ2ikdGLtyVXZRqgGHWOMlBPVSKjYLb6NMZmAeHhAsGNjiQ3vP5VEdb_ULA9S5Lpo8H7-ElhKufmlVqQ6CrDyTUsyQeZ3IzbNCbN8MBLFhgRxVMZSwyl640YXF9ZvQUI1sibP-Ko86xrin_2EXEmAdEk7aSl9u0ezlmnBL6Wk8a7CwSJUEUAwAjrNdJTLSodjQaiVVx7TZ0rQEkzPgceaH7wtpmvl–6txmRDnBu4g0na3Km19K1LNzs0fz7-_Go8Qlg=’, ‘deviceid’: ‘957933bd-cdc4-4876-ad00-bc00a1d55c29’, ‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 …

Total answers: 1

How do you get tkinter to work with asyncio?

How do you get tkinter to work with asyncio? Question: How do you get tkinter to work with asyncio? My studies suggest this general question does resolve into the specific problem of getting tkinter to await a coroutine function. Context If tkinter’s event loop is blocked the loop will freeze until the blocking function returns. …

Total answers: 1

Can I make an asynchoronous method in python?

Can I make an asynchoronous method in python? Question: I have started learning about async in python. But in examples, I only see people use async keyword in functions. I wonder if I can use it with methods? Here is what I tried: import asyncio class asyncClass: async def asyncMethod(self): print("Starting") await asyncio.sleep(1) print("Ending!") class1 …

Total answers: 1

Why I can not insert more than 165 rows into a sqlite database asynchronously?

Why I can not insert more than 165 rows into a sqlite database asynchronously? Question: I was playing around with aiosqlite. I wrote this code to insert 1000 rows into a database: import asyncio import aiosqlite import inspect import signal signal.signal(signal.SIGINT, signal.SIG_DFL) counter = 1 async def write_to_db(number): global counter db = await aiosqlite.connect(‘test_database.db’) command …

Total answers: 1

Async Generator says it doesn't implement __anext__, when it does

Async Generator says it doesn't implement __anext__, when it does Question: First time using the Aync Generators. I’m using Python 3.9. This is my implementation: import asyncio class SubEventStream(): def __init__(self) -> None: self.queue = asyncio.Queue() return async def __aiter__(self): return self async def __anext__(self): return await self.pop() async def append(self, request): return await self.queue.put(request) …

Total answers: 2

Discord.py: How to send a message without using async and await

Discord.py: How to send a message without using async and await Question: How can I create a function (without async) that sends a message to a specific channel every time it (the function) gets executed somewhere in the code? def sendMsg(): channel = client.getChannel(Channel id) message.channel.send("example message") #excecuting the function sendMsg() Doesn’t do anything async …

Total answers: 3

Python async Playwright pass data outside function

Python async Playwright pass data outside function Question: I’m quite new to aynschronous programming and I just can’t get the json data out of the function. Is there some kind of special way to pass on data from async functions? I would like to use the json data to extract other data. async def main(): …

Total answers: 2