Closed HufflyCodes closed 4 weeks ago
Hi @HufflyCodes, I'm not the expert, but it seems like Windows does not support "keyboard_handler" in asyncio.
If anyone knows how to get around with this, please let us know.
Hi @HufflyCodes, I am wondering if the msvcrt
module would be any help, see this discussion.
Otherwise, a possible workaround would be to remove the add_reader
line (and the handler function) as you have done, and instead get the consumer task to time out and set the quitclient
event when no data is added to the queue for a certain time. For that, you'd need to replace the lines
frame = await queue.get()
if frame[0]=='QUIT': # intercept exit signal
break
with something like this:
try:
# raises TimeoutError if the queue is still empty after 10 seconds
frame = await asyncio.wait_for(queue.get(), timeout=10)
except asyncio.TimeoutError:
quitclient.set()
break
and define the quitclient
event globally, or pass it to both tasks.
At this point, the last three lines of run_ble_client
are no longer needed:
### remove these lines
loop.remove_reader(sys.stdin)
# signal the consumer task to quit
queue.put_nowait(('QUIT', None, None, None))
I have not tried it, but barring mistakes I think it should work. The program should quit by itself when the user takes off the sensor (or the sensor disconnects)
Hope this helps! Fabrizio
Thanks for raising this issue, i was scratching my head, and commenting out the line enabled my Coospo 808s to work on the heartrate_callback
example
Thanks @alex-ong for testing it on the Coospo device!
@HufflyCodes and @MarkSttc , I have now modified the examples so that they use a separate thread for keyboard input under windows.
I'll close this issue, as I think this is now solved Fabrizio
Been a bit since I have updated anything here as I was going through testing BleakHeart on Windows 10 but one issue I did run into right off the bat was the keyboard handler AsnycIO reader on line 67 in the ECG Queue example prevents the program from starting up. While that's a nice feature for sure but my current work around is just commenting out
loop.add_reader(sys.stdin, keyboard_handler)
I haven't had the time to fully check why this is an issue on Windows 10 as I am fairly new to AsyncIO so when I get around to doing a deeper dive I will look into it further.