6

Feeling the need to learn how to use asyncio, but cannot think of applicable problem (or problem set) that can help me learn this new technique.

Could you suggest a problem that can help me understand and learn asyncio usage in practice?

In another words: can you suggest me an example of some abstract problem or application, which, while coding it, will help me to learn how to use asyncio in practice.

Thank you

Xeizzeth
  • 441
  • 1
  • 3
  • 10
  • 1
    Try implementing [netcat](http://netcat.sourceforge.net/) using [cat](https://en.wikipedia.org/wiki/Cat_%28Unix%29), [asyncio subprocess](https://docs.python.org/3/library/asyncio-subprocess.html) and [asyncio streams](https://docs.python.org/3/library/asyncio-stream.html). Or a [web crawler](http://aosabook.org/en/500L/a-web-crawler-with-asyncio-coroutines.html). – Vincent Jul 27 '17 at 12:50
  • Thank you. Will try to do that. – Xeizzeth Jul 27 '17 at 13:03
  • Write crawler that collects all links on site, starting from main page (choose little site to test). Crawler should request urls parallely (using aiohttp for example, see https://stackoverflow.com/a/35900453/1113207 ). Use semaphore to limit count of parallel connections. https://docs.python.org/3/library/asyncio-sync.html#asyncio.Semaphore – Mikhail Gerasimov Jul 27 '17 at 14:37
  • Thank you Mikhail, will try to do that. – Xeizzeth Jul 27 '17 at 16:08

1 Answers1

2

Any I/O bound task would be a good case for asyncio. In the context of the network programming - any application, that requires simultaneous handling of the thousands of connections. Web server, web crawler, chat backend, MMO game backend, torrent tracker and so on. Keep in mind, though, that you should go async all the way and use async versions of all libraries performing blocking I/O, like the database drivers, etc.

otykhonruk
  • 181
  • 7