Skip to content

Tag: python-asyncio

If I use a helping function for a command, should I use await to call my helping function or just transfer control to my async helper

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

How to nullify python asyncio global variables?

I am writing a personal Telegram Bot to collect statistics on my accounts The main task of the bot is to send async requests to the API and display information via Telegram. Everything works as it should, but the problem is with global variables, or rather, their incorrect counting. An example of one of my functions: Function result: Bot

Asyncio Streams automatically restarts to read data even after writer.close() is run

I followed the tutorial in to read data from a sensor (TCP protocol, PC as the server): The program is supposed to finish after 1 second data transmission. However, the output is: It repeated automatically and infinitely. What is the reason for this and How could I solve it? Answer Problem serve_forever() listens to the port indefinitely. So, even

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