Created
December 4, 2017 05:43
-
-
Save narzeja/cef5357152e48ecdff20be4eb100c3d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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