Skip to content

Instantly share code, notes, and snippets.

@zsrinivas
Created September 24, 2016 06:57
Show Gist options
  • Save zsrinivas/e239fa0d30c55dee6a434e52ca61d5a0 to your computer and use it in GitHub Desktop.
Save zsrinivas/e239fa0d30c55dee6a434e52ca61d5a0 to your computer and use it in GitHub Desktop.
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