-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MacOS: cannot use BleakScanner with an event loop in another thread #242
Comments
The #206 resolution was all @dlech, I merely did the merging of it. This was unfortunate. The I haven't got a 10.15 Mac available for the coming 10 hours, but I will look into it after that. I think it is due to that the As proposed in #224 the explicit handling of loops should (and will) be removed in Bleak. Have you tried runing the code with |
Since I need a second thread, and event loops are per-thread, I have to get the one associated with I did try changing (I now have a whole slew of new problems related to MacOS returning a UUID instead of an actual address, but those are mine to figure out.)
As long as I can get the event loop when I need it, that's ok. The |
Yes, everything related to bleak needs to be done in the thread after the new event loop is created.
This is a known issue. Apple does not make the Bluetooth address available anywhere for security/privacy reasons. |
Yes, thanks, this is something I was not looking forward to tackling. Our CircuitPython libraries make a lot of assumptions about having the address available, and I'll have to think about how to get around this. Perhaps I'll generate a fake address that hashes the UUID down to 48 bits. We have even seen devices we can identify only based on their advertised address. But that's another topic. |
Does it mean that you regard this issue as resolved, or would you like to see some changes to how the event loops are handled? There will be changes to event loop handling in version 0.8.0 which will possibly have breaking changes. You might have to revisit the things you decide to implement now, but my intention is to leave the 0.8.0 release branch open for some days to test before releasing it to PyPI. Regarding the Bluetooth addresses on Mac, there was issue #140 where @5frank did some preliminary exploration around this. He might have discovered more since then. |
I think it is resolved, except for adding documentation (emphasis below). @dlech can comment if there's anything to fix with regard to the @dlech says:
This is the key point I did not realize, since this restriction isn't necessarily true on the other platforms (or at least my code works by accident on those platforms). It would be good to mention this somewhere in the documentation; that's probably the only action item from this issue.
Thanks, I'll certainly test 0.8.0 and modify our code as necessary when it comes out
Thanks for that reference. MacOS/iOS are pretty strict about this security. I'm not sure we want to change our current _bleio API to accommodation a generic ID scheme solely because core Bluetooth works that way, but I think we can work around it somehow. |
No, I don't think there is anything to fix here.
Previously, if using the |
In the |
Regarding this as done, with the release of version 0.8.0. Good work and thanks for the input on this issue! |
Thanks for the 0.7.0 release! I no longer have the #206 issue, but due to the way we're using
BleakScanner
, we're now getting a different error, this time about an internal thread event bleak is using.I've distilled it down to the test program below. It creates a new event loop in a new thread, and then passes that loop to
BleakScanner()
to use. This may seem unnecessarily complex, but in the real code we need another thread to allow scanning results to be returned incrementally to the caller.This program runs fine on Linux under bluez.
The backtrace is below the program:
This backtrace is generated:
The text was updated successfully, but these errors were encountered: