jalmeroth / homie-python

A Python-implementation of the homie v2 convention.
https://github.com/marvinroger/homie
54 stars 15 forks source link

Remove signal dependency #44

Closed bodiroga closed 5 years ago

bodiroga commented 6 years ago

Hi @jalmeroth!

How are things going on? :+1:

I'm writing a new app/script using the homie-python library but I have encountered a problem with the usage of the "signal" module. My app uses different threads and creates homie devices dynamically, but I'm getting the following error when instantiating a new homie device:

File "/home/aitor/git/bluetooth-remote-to-homie/homie_bluetooth.py", line 16, in __init__
    self.homie_ = homie.Homie(self.homie_info)
File "/usr/local/lib/python3.5/dist-packages/homie/main.py", line 59, in __init__
    signal.signal(signal.SIGTERM, self._sigTerm)
File "/usr/lib/python3.5/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

Do you think that the signal module is necessary for the library? The "_sigTerm" and "_sigHup" functions just print a debug message and they rise the "SystemExit" exception, nothing critical.

What is your opinion about removing the signal dependency? I can submit a PR to address this topic, it's just a matter of removing 11 lines of code :wink:

Best regards,

Aitor

jalmeroth commented 6 years ago

Hi @bodiroga,

thanks for raising this issue! I think you have identified some legacy code here. 👍 Since all threads are daemonized now, it looks like this is no longer necessary. If you are willing to provide a PR, I would be happy to merge it.

Thanks again, Jan