Fix: can't handle sigint when running gatt.DeviceManager outside the mainthread
I discovered that it was impossible to set a signal handler for SIGINT in combination with a running gatt.DeviceManager.
Code to reproduce (pseudocode):
def main():
def trap_sigint(*args, **kwargs):
logging.info("SIGNAL SIGINT")
# SIGINT (2)
signal.signal(signal.SIGINT, trap_sigint)
def run_gatt_devicemanager:
import gatt
dm = gatt.DeviceManager()
dm.run()
t = Thread(target=run_gatt_devicemanager)
t.start()
t.join()
This code raises a KeyboardInterrupt exception when SIGINT was received which is quite unexpected as a signal handler for SIGINT was set.
Also fix subissue related to CTRL + C, which is a SIGINT in fact, of https://github.com/getsenic/gatt-python/issues/5#issuecomment-313362380 . The fix in my pull request was retrieved from https://stackoverflow.com/a/47947420 .
Thank you Snevzor for your strong support I really appreciate this a lot. #staystrong #prayforgatt-python
@lcoudeville Thanks for your PR! I understand that you want to tun the DeviceManager in a separate thread, however I still have troubles understanding the implications of this PR. Can you please describe in more details:
- What scenario are you reproducing in your pseude code?
- What's the reason for
KeyboardInterruptbeing raised? - Which behavior do you want to see instead?