Mocking async call in python 3.5

How do I mock async call from one native coroutine to other one using unittest.mock.patch? I currently have quite an awkward solution: class CoroutineMock(MagicMock): def __await__(self,...

How to set class attribute with await in __init__

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): ...

Asyncio.gather vs asyncio.wait

asyncio.gather and asyncio.wait seem to have similar uses: I have a bunch of async things that I want to execute/wait for (not necessarily waiting for one to finish before the next one starts)....

python asyncio add_done_callback with async def

I have 2 functions: The first one, def_a, is an asynchronous function and the second one is def_b which is a regular function and called with the result of def_a as a callback with the...

"Asyncio Event Loop is Closed" when getting loop

When trying to run the asyncio hello world code example given in the docs: import asyncio async def hello_world(): print("Hello World!") loop = asyncio.get_event_loop() # Blocking call which...

Why coroutines cannot be used with run_in_executor?

I want to run a service that requests urls using coroutines and multithread. However I cannot pass coroutines to the workers in the executor. See the code below for a minimal example of this...

python-asyncio TypeError: object dict can't be used in 'await' expression

I am using a third party module to retrieve data from an API. I simply would like to asynchronously await the module to return the data which occasionally takes several seconds and freezes up my...

PIL and blocking calls with asyncio

I have an asyncio app which uses server from aiohttp and async sockets with asyncio.open_connection() My code contains some blocking calls from the PIL library...

How can I wait for an object's __del__ to finish before the async loop closes?

I have a class that will have an aiohttp.ClientSession object in it. Normally when you use async with aiohttp.ClientSession() as session: # some code The session will close since the...

RuntimeError: run loop already started in pyttsx

I am creating a DIY virtual assistant for fun and exercise in python. I run into a problem when trying to use engine.say in a thread and then use it again in my main program. I already tried to...

How to aiohttp request post files list python requests module?

I want to multi post using aiohttp. And, I need post with FILE. But, my code dosen't work This is my code import aiohttp file = open('file/path', 'rb') async with aiohttp.request('post', url,...

Jupyterhub - ERROR:asyncio:Task exception was never retrieved

I'm not able to install Jupyterhub using pip. I tried reinstall, but no matter what, I'm still getting asyncio Error. Any idea what I'm doing wrong ? [[email protected] bin]# which...

SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108) Discord/python

I'm using Pycharm and python 3.8 and latest version of discord. I tried to run this script but got this error. Can anyone help? import discord TOKEN = 'xxxxx' client =...

Using Multiple Asyncio Queues Effectively

I am currently building a project that requires multiple requests made to various endpoints. I am wrapping these requests in Aiohttp to allow for async. The problem: I have three Queues: queue1,...

asyncio.run RuntimeError: Event loop is closed

import robloxapi, asyncio client = robloxapi.Client(".ROBLOSECURITY Cookie Here") # Removed this for security reasons async def main(): user = await client.get_self() try: role =...

Possible to run async function using exec?

I am trying to call an async function from exec, I would expect it to work like: def test(): print("test") exec('def test2():\n print("test")\ntest2()') test() Output: test test So a...

Python 3 asyncio with aioboto3 seems sequential

I am porting a simple python 3 script to AWS Lambda. The script is simple: it gathers information from a dozen of S3 objects and returns the results. The script used multiprocessing.Pool to gather...

How can I send an HTTP request from my FastAPI app to another site (API)?

I am trying to send 100 requests at a time to a server http://httpbin.org/uuid using the following code snippet from fastapi import FastAPI from time import sleep from time import time import...

How to convert grpc.ServerInterceptor to grcp.aio.ServerInterceptor

I am trying to implement async ServerInterceptor [grcp.aio.ServerInterceptor]. My current synchronous ServerInterceptor looks like this...

Sharing python objects across multiple workers

We have created a service using FastAPI. When our service starts it creates a few python objects that the endpoints then use to store or retrieve data from. FastAPI in production starts with...

How to run coroutine function when use sync_to_async in django?

I have add_event method that calls _post method as async using sync_to_async in django. but when I test the method inside of Django shell, it does not even run my async _post function and returns...

Telethon - The server closed the connection error

I'm unable to connect to Telegram using Telethon. from telethon import TelegramClient import logging api_id = 1111111 api_hash = 'd0111111111111111111111111111111' client =...

Cannot pip install mediapipe on Macos M1

Hello fellows I'm using mac air with M1 chip My env sets like (CV) san  ~/work/python  conda list # packages in environment at /Users/san/miniforge3/envs/CV: # # Name ...

SQLAlchemy v1.4 ObjectNotExecutableError when executing any SQL query using AsyncEngine

I'm using async_engine. When I try to execute anything: async with self.async_engine.connect() as con: query = "SELECT id, name FROM item LIMIT 50;" result = await...

Why redis stream consumers should specify an individual name in the same consumer group?

The codes below show how I test the Redis stream functions. And I found that different processes with the same consumer name are competing to consume messages in the same stream. In my...

TypeError: 'coroutine' object is not subscriptable

I am trying to create a discord bot with python as language and mongodb as database. I am creating this command to update the troops amount but when I run this command it shows TypeError:...

IB-Insync only place Stk order once (will not execute additional buy or sell)

I am trying to implement a Tradingview/Interactive Brokers API using IB-Insync to automatically place orders with Interactive Brokers TWS via tradingview webhook alerts. I have consumed a lot of...

how to access relationships with async sqlalchemy?

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...

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'dislike_count'

Ignoring exception in command play: Traceback (most recent call last): File "C:\Users\rcesa\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in...

How to use AsyncIOScheduler to run function from another function?

I'm having difficulty to understand how the AsyncIOScheduler works and how I can schedule a function inside the main function, or how is the proper way to do that. How can I run the function foo...