Issue
According to asyncio synchronization primitives, there are synchronization methods.
- I am getting confused about why we need synchronization in asyncio?
- I mean, asyncio is asynchronous.
- Is it meaningful to add something synchronous in asynchronization?
Solution
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
.
Answered By - Mikhail Gerasimov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.