Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def make_stream():
- loop = asyncio.get_event_loop()
- queue = asyncio.Queue()
- def callback(message):
- loop.call_soon_threadsafe(queue.put_nowait, message)
- async def stream():
- while True:
- yield queue.get()
- return callback, stream()
- async def print_messages():
- # print messages as they come
- cb, stream = make_iter()
- mido.open_input(callback=cb)
- async for message in stream:
- print(message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement