I have a command that works to send multiple type of messages that follow the same structure but I am using a helping function to send the message. For simplicity, my code looks similar to this: Option 1: Option 2 is making every function async and calling helper with await. It is my first time creating a discord bot and
Tag: async-await
websocket await close vs await wait_closed
I’m using the websockets package on python and I’m opening a connection as a client, but NOT in a block context like this: I’m opening the connection like this: The thing is that I don’t under stand what is the right way to close the connection. The document explains here about await close() and await wait_closed(), but I don’t understand
async_generator’ object is not iterable
I need to return a value in async function. I tried to use synchronous form of return: output: 0 [Finished in 204ms] But it just return value of the first loop, which is not expexted. So changed the code as below: output: TypeError: ‘async_generator’ object is not iterable by using async generator I am facing with this error. How can
Proper way to cancel remaining trio nursery tasks inside fastAPI websocket?
I’m still quite new to websockets and I’ve been given a problem I’m having a hard time solving. I need to build a websocket endpoint with FastAPI in which a group of tasks are run asynchronously (to do so I went with trio) with each task returning a json value through the websocket in realtime. I’ve managed to meet these
Tornado gives error Cannot write() after finish()
I am using the Tornado chat demo example from here: https://github.com/tornadoweb/tornado/tree/master/demos/chat and just altering it very slightly. The code change is just a small class called Connections and a bit in the MessageNewHandler(). All I am doing is just saving a reference to self and trying to write(message) to a previous client. But when I go to save on this
Use the same websocket connection in multiple asynchronous loops (Python)
I am running two loops asynchronously, and want both to have access to the same websocket connection. One function periodic_fetch() fetches some data periodically (every 60 seconds) and sends a message to the websocket if a condition is met. The other retrieve_websocket() receives messages from the websocket and perform some action if a condition is met. As of now, I
Discord.py with threads, RuntimeError: Timeout context manager should be used inside a task
So I’m creating a discord bot that is constantly scraping a webpage, checking if the item is in stock. When the item becomes in stock, send a message in the chat. Since the scraping is in a constant loop, I figured I would put that in a thread, one for each page that needs to be scraped. The problem is
How to call Python async function from Rust?
I have read this answer(How to call Rust async method from Python?) and what I want to do is the opposite of this. I want to call a Python async function and await it in tokio’s runtime. Is it possible? I have given it some tries but I am facing an error in the output. This is how my python
Asynchronous code failure when connecting to redis
I created a small class to perform basic operations with redis, using aioredis. And a test handler to call the write/read operation for redis But get error I guess the problem could be that the asynchronous code has to be run through an event loop But I can’t understand how I can build this logic into my code Answer Your
Python – getting lost around async
As the title said – I’m having a problem with async stuff. What I’m trying to achieve is written under every function. Sadly in this state of code I’m getting and error: TypeError: object StreamReader can’t be used in ‘await’ expression and at the end RuntimeError: Event loop is closed I was googling for a while and didn’t really find