S
S
Sazoks2021-03-11 08:58:56
Python
Sazoks, 2021-03-11 08:58:56

Resources for learning async in Python?

Good day everyone!
The problem is this. I am a freshman, and my classmates and I were given a project to design a competition ground for students. Example: people upload their solutions (algorithms) to the server, snakes in the Snake game of the same name compete with each other, each under the control of their own algorithm.
It is necessary to make a "broadcast" of the game to clients. We decided to do it through websockets, but we can’t figure out asynchrony in python ...
I worked with TCP in C ++ (winsocks and qsockets) and tried to draw an analogy, but here, as I understand it, there is a completely different protocol (websockets), and my idea to accept connections in one thread, write them to an array, and then in another thread in a loop just send data (new coordinates of snakes) did not work.

All in all, I really need your help. Sorry for such an abundance of text, I hope the question will not be deleted, but I already googled everything and still didn’t manage to understand the asynchrony(

Thanks in advance to everyone and have a good day!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2021-03-11
@bacon

By the condition, it turns out that only the server sends data, so websockets is redundant, SSE is enough. On the other hand, it is easier for websockets to find ready-made libraries, for example https://docs.aiohttp.org/en/stable/web_quickstart....
And how to learn, start with off-docs https://docs.python.org/3/library /asyncio.html and google already specific incomprehensible moments.

I already googled everything and still did not manage to understand the asynchrony (
Well, again, it's better to ask a more specific question, what exactly is not clear.

V
Vindicar, 2021-03-11
@Vindicar

As for resources, I really liked the explanation here (first part, link to continuation at the end of the text):
https://krondo.com/in-which-we-begin-at-the-beginning/
In English, but written in simple. In addition, the author writes, although at length, but consistently shows where the concept of asynchronous programming came from, in response to what tasks it was invented, and how it simplifies these tasks. In fact, in the course of this article, we are reinventing the wheel in order to understand how cool it is to ride a motorcycle. =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question