Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. # following <https://stackoverflow.com/a/49333864>
  2.  
  3. import asyncio, threading
  4.  
  5. def render(loop):
  6.  
  7.     async def test():
  8.         await asyncio.sleep(2)
  9.         print("hi")
  10.         return 200
  11.  
  12.     future = asyncio.run_coroutine_threadsafe(test(), loop)
  13.     result = future.result()
  14.     return result
  15.  
  16. loop = asyncio.get_event_loop()
  17. threading.Thread(target=loop.run_forever, daemon=True).start()
  18.  
  19. result = render(loop)
  20. print("result of async coroutine is:", result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement