HIPPO LD
HIPPO LD

Reputation: 509

Why we need asyncio synchronization primitives, when to use these?

According to asyncio synchronization primitives, there are synchronization methods.

Upvotes: 9

Views: 2264

Answers (1)

Mikhail Gerasimov
Mikhail Gerasimov

Reputation: 39536

Synchronization primitives don't make your code synchronous, they make coroutines in your code synchronized.

Few examples:

  • You may want to start/continue some coroutine only when another coroutine allows it (asyncio.Event)
  • You may want some part of your code to be executed only by single coroutine at the same time and other to wait for their turn (asyncio.Lock)
  • You may want some part of your code to be executed only by limited number on coroutines at the same time (asyncio.Semaphore)

Take a look at a practical example of using asyncio.Semaphore.

Upvotes: 12

Related Questions