J
J
jslby2020-11-22 01:48:10
MySQL
jslby, 2020-11-22 01:48:10

How to deal with async correctly in python?

Hello dear experts!
The abundance of different approaches presented on the Internet about this is simply huge and it seems that everything changes with each minor version of python.
If you have the time and opportunity, you can describe a simple example of asynchronous programming in python.
For example: there is a database with a large number of records (mysql). There is a site from which we will parse data.
How to correctly implement such an algorithm:

  • in the worker we get a record from the database and immediately delete it in one transaction
  • send a request to the site with a parameter from the database
  • print data to terminal

I have a main gag in understanding competition and how to correctly organize the simultaneous work of, say, 5 workers in asynchronous mode without terminating the script - the only way out is by an exception in the worker when the entries in the database are over.

With threads, this is quite simple to implement, but asynchronously I can’t understand at all.

ps before that, a lot of experience with the node, but never faced competition. I decided to study python as part of self-study and enrichment. It’s not difficult for anyone, please help with understanding, I re-read a single article and a single page of the

pps documentation, I don’t need to write the whole time, at least the main template, I need to understand. the task is fictitious and has no practical value

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-11-22
@bacon

https://qna.habr.com/answer?answer_id=1805453#answ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question