Skip to content

Instantly share code, notes, and snippets.

@Sraw
Created December 25, 2017 09:00

Revisions

  1. Sraw created this gist Dec 25, 2017.
    6 changes: 6 additions & 0 deletions index.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    `asyncio` won't automatically create event loop for sub-thread, so to run async tasks in sub-thread, we need to manually create an event loop first.

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    asyncio.ensure_future(task())
    loop.run_forever()