ukBaz / python-bluezero

A simple Python interface to Bluez
MIT License
395 stars 112 forks source link

No clean shutdown method on Peripheral #341

Closed dsjove closed 3 years ago

dsjove commented 3 years ago

Please a a stop method on Peripheral. The only way to shut down the self.mainloop.run() is via a KeyboardInterrupt exception.

ArthurKun21 commented 3 years ago

https://github.com/ukBaz/python-bluezero/issues/332#issuecomment-846437271

ukBaz commented 3 years ago

I would suggest that the ctrl-c does close the peripheral down cleanly. If you mean that you want to do it programmatically, then @RulerKun has linked to information on how this can be done.

As a reminder, the goal of this library was to help users get started with Bluetooth on Linux (Raspberry Pi). In the docs it talks about the different levels of API that people can use to access finer control. People have the option to use the BlueZ API's directly to get the control they require.

With the Peripheral I had the scenario in mind that people would be creating embedded devices. I envisioned that people would have a headless device that would launch the Peripheral at boot and run until the machine was closed down. I am not against adding some command that shuts the peripheral down. It just needs to be implemented, tested, and supported.

dsjove commented 3 years ago

I really like the Peripheral class. :-) It does nearly everything I have needed so far. I think I can get to the clean shutdown via the adaptor.

I am building an over-engineered model train. It can be issued a shutdown command remotely for the stop everything. I am doing a kill-9 as last step from the python code.

dsjove commented 3 years ago

I would very much like to create pull requests for these changes. I can make them. But I am a bit of a python noob and did not know how to undo the pip install of BlueZero, and fork it onto the raspberry device in an "installed" way.

ukBaz commented 3 years ago

Part of the challenge here for me is that "clean shutdown" and "stop everything" are very imprecise terms. More helpful would be terms like "stop advertisement" or "make peripheral non-connectable" as these describe the functionality that the peripheral code controls.

kill -9 is more of an emergency ejector seat rather than a nice controlled exit. I would be wary of this being a good solution.

As to how to create a pull-request, there should be plenty of information around on how to do this. On Bluezero we are using a fork and pull model. This is common workflow for open source projects on GitHub so there are plenty of tutorials around. The challenge can be that different tutorials can do it slightly differently because they use alternative tools or slight variations on the flow. The good news is that you can't mess up the Bluezero main repository so you can jump in and experiment.

pip uninstall should be what you need to remove the PyPI Bluezero version.

ukBaz commented 3 years ago

@dsjove Should I close the ticket or is there more to come on this?