peterhinch / micropython-async

Application of uasyncio to hardware interfaces. Tutorial and code.
MIT License
742 stars 168 forks source link

Delay_ms cancel and cancel again #98

Closed stephanelsmith closed 1 year ago

stephanelsmith commented 1 year ago

In Delay_ms, if canceled and cancled again, you get and error that you cannont cancel() "None".

    def deinit(self):
        self.stop()
        self._mtask.cancel()
        self._mtask = None

Recommending:

Similar to the issue raised in the micropython issues area regarding gather, getting into the weeds of reliability. Would prefer to make deinit "safe" as I would like to not have to wrap all calls like this in try/except blocks.

Appreciate your consideration! Happy to put together a PR.

peterhinch commented 1 year ago

This seems simplest:

    def deinit(self):
        if self._mtask is not None:
            self.stop()
            self._mtask.cancel()
            self._mtask = None
stephanelsmith commented 1 year ago

Agreed, I'll put a PR together tomorrow. Much appreciated for taking a look.

peterhinch commented 1 year ago

Fix now implemented. Thanks for pointing this out.

stephanelsmith commented 1 year ago

Ya beat me to it! Just getting a chance tonight. Much appreciated. Thank you.