Skip to content

Instantly share code, notes, and snippets.

@bukowa
Created August 7, 2019 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bukowa/2ff7e10a62da115da0497f0b70d9353a to your computer and use it in GitHub Desktop.
Save bukowa/2ff7e10a62da115da0497f0b70d9353a to your computer and use it in GitHub Desktop.
async loop
import asyncio
import time
sema = asyncio.Semaphore(value=5)
async def worker():
async with sema:
print("Start")
await asyncio.sleep(3)
print("Finish")
async def add():
while True:
await asyncio.sleep(0)
async with sema:
asyncio.ensure_future(worker())
async def main():
asyncio.ensure_future(add())
loop = asyncio.get_event_loop()
asyncio.ensure_future(main())
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment