Skip to content
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

Fix: can't handle sigint when running gatt.DeviceManager outside the mainthread #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lcoudeville
Copy link

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 #5 (comment) . The fix in my pull request was retrieved from https://stackoverflow.com/a/47947420 .

@lcoudeville
Copy link
Author

Thank you Snevzor for your strong support I really appreciate this a lot. #staystrong #prayforgatt-python

@larsblumberg
Copy link
Contributor

@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 KeyboardInterrupt being raised?
  • Which behavior do you want to see instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants