--
You received this message because you are subscribed to the Google Groups "python-bleson" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-bleson+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/python-bleson/344bc909-d700-4b78-8de1-a91ea2709c37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Barry,
Thanks for kicking the tyres.
The thing that not sitting right at the moment is the fact that in the current experiment the observer.start() method doesn't return as it starts the main loop (a RunLoop on macOS).
I've tried to find a way to initiate the runloop on a background thread, and to do this without having to changing the bleson public API or by introducing a 3rd party library. But, although I can start the runloop on a background thread, I'm not receiving CoreBluetooth events when I do.
A few key facts:
a) 'bleson' is currently Python 3.x only, by design. (I also think not requiring additional library installs is a big bonus)
b) macOS comes bundled with Python 2.7 with PyObjC pre-installed, but not a version of Python3.
c) If this was a pure Obj-C app the 'runloop' responsible for receiving CoreBluetooth events should, in theory, be able to run from a background thread, but doesn't seem possible using PyObjC, I've raised: https://bitbucket.org/ronaldoussoren/pyobjc/issues/215/starting-runconsoleeventloop-from-a
d) As an alternative to using PyObjC there is a XPC Python wrapper. XPC is Apple's form of light-weight IPC, Sandeeps Noble library uses CPC on macOS. However, the Python XPC module I've found has installation/build (PY2/Py3) issues that I've overcome and runtime Unicode issues (Py3 only) that require more investigation. https://github.com/matthewelse/pyxpcconnection
The alternates that I see:
1. Change the Bleson API to be more like Adafruit Python LE library, i.e. bleson starts the platforms 'mainloop' and runs the users code on a secondary thread (specified by a user provided callback)
2a. Support Python 2.x so not to require the additional installation of PyObjC step, and change the bleson API
2b. Support Python 2.x so not to require the additional installation of PyObjC step, but NOT change the bleson API and (hopefully resolve the runloop issue
3 Switch to XPC. Would not require API change but requires fixing it in the process and an additional install step that requires building a native components.
Questions:
Is changing the Bleson API to call user code on a background thread the way to go?
Is it worth the effort of supporting Python2?
Is it worth the potential pain of adopting an XPC library?
Is there another way?