Skip to content

Instantly share code, notes, and snippets.

@alex-eri
Created March 13, 2020 09:38
Show Gist options
  • Save alex-eri/9b1a028ce5d12a962957beeba86803b2 to your computer and use it in GitHub Desktop.
Save alex-eri/9b1a028ce5d12a962957beeba86803b2 to your computer and use it in GitHub Desktop.
import asyncio
loop = asyncio.get_event_loop()
sema = asyncio.Semaphore(value=10)
async def send(msg):
print(msg)
async def income(msg):
if not sema.locked():
await sema.acquire()
await send(msg)
loop.call_later(5, sema.release())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment