-
-
Save zsrinivas/e239fa0d30c55dee6a434e52ca61d5a0 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 threading | |
import asyncio | |
from functools import partial | |
async def task(count, stime): | |
await asyncio.sleep(stime) | |
print ('%s: %s' % (threading.current_thread().name, count), flush=True) | |
def multi_event_loops(): | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
t1 = task(1, 6) | |
t2 = task(2, 3) | |
loop.run_until_complete(asyncio.gather(t1, t2)) | |
def creepy(): | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
t1 = task(10, 25) | |
loop.run_until_complete(t1) | |
def main(): | |
threading.Thread(target=creepy).start() | |
for _ in range(3): | |
threading.Thread(target=multi_event_loops).start() | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment