Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save narzeja/cef5357152e48ecdff20be4eb100c3d1 to your computer and use it in GitHub Desktop.
Save narzeja/cef5357152e48ecdff20be4eb100c3d1 to your computer and use it in GitHub Desktop.
import time
import asyncio
from functools import partial
from asyncio import coroutine
from concurrent import futures
def do_something(sleeping):
time.sleep(sleeping)
print("sleeping: ", sleeping)
return sleeping
def main():
loop = asyncio.new_event_loop()
futs = []
try:
with futures.ProcessPoolExecutor(max_workers=10) as executor:
for i in range(10):
part = partial(do_something, i)
future = loop.run_in_executor(executor, part)
futs.append(future)
fut = asyncio.gather(*futs)
result = loop.run_until_complete(fut)
print(result)
finally:
loop.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment