Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

change to enable this library to run in background threads and processes #35

Closed
wants to merge 1 commit into from

Conversation

JeanRintoul
Copy link

After trying to run this library as well as a web gui front end I realized that the bluetooth cannot possible run in a thread, process, child sub process and the problem is fixable by adding the following lines to the provider.py initialize function in the CoreBluetoothProvider class.

    dispatch_queue = libdispatch.dispatch_queue_create(b'q', None)

    self._central_manager.initWithDelegate_queue_options_(self._central_delegate,
                                                          dispatch_queue, None)

More details can be seen from this stack overflow post:
https://stackoverflow.com/questions/48958267/how-can-i-use-corebluetooth-for-python-without-giving-up-the-main-thread?fbclid=IwAR3X9aaK4kAu-BKFJ3yFDM48CMxiJQmw39GhDxnWeXpxKNKnCNUNOzYSZpk

Merging this in will make the library much more robust for a range of application where the bluetooth runs in the background.

@seanngpack
Copy link

seanngpack commented Nov 24, 2019

@JeanRintoul
Could you provide some insight on how you achieved threading with your main loop and this library?
I'm trying something similar where I have a main loop perform some actions, then ask my Arduino to perform a task, wait for that task to finish, then continue on the main loop.

I'm mainly confused on the docstrings in provider.py saying you can omit the self.ble.run_mainloop_with() method if you're running a GUI or application where you have a main loop. But how does your CoreBluetoothProvider object have the needed information (self._user_thread = None) if you're not using this method?

Nevermind, got it. Instead of running ble.run_mainloop_with() I created my own thread.

@dhalbert
Copy link
Contributor

dhalbert commented Nov 2, 2020

This library has been deprecated. Please update to use this new library:
https://github.com/adafruit/Adafruit_Blinka_bleio
PR's can be submitted to the new library.

@dhalbert dhalbert closed this Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants