Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. async def make_stream():
  2. loop = asyncio.get_event_loop()
  3. queue = asyncio.Queue()
  4. def callback(message):
  5. loop.call_soon_threadsafe(queue.put_nowait, message)
  6. async def stream():
  7. while True:
  8. yield queue.get()
  9. return callback, stream()
  10.  
  11. async def print_messages():
  12. # print messages as they come
  13. cb, stream = make_iter()
  14. mido.open_input(callback=cb)
  15.  
  16. async for message in stream:
  17. print(message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement