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

Release/0.19.2 #1116

Merged
merged 6 commits into from Nov 6, 2022
Merged

Release/0.19.2 #1116

merged 6 commits into from Nov 6, 2022

Conversation

dlech
Copy link
Collaborator

@dlech dlech commented Nov 6, 2022

Fixed

dlech and others added 6 commits November 6, 2022 15:06
Python 3.11 crashes on Windows when connecting to a device:

    Traceback (most recent call last):
    File "C:\Users\david\Documents\GitHub\Pybricks\bleak\examples\service_explorer.py", line 64, in <module>
        asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS))
    File "C:\Users\david\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
        return runner.run(main)
            ^^^^^^^^^^^^^^^^
    File "C:\Users\david\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
        return self._loop.run_until_complete(task)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\david\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete
        return future.result()
            ^^^^^^^^^^^^^^^
    File "C:\Users\david\Documents\GitHub\Pybricks\bleak\examples\service_explorer.py", line 29, in main
        async with BleakClient(address) as client:
    File "C:\Users\david\Documents\GitHub\Pybricks\bleak\bleak\__init__.py", line 433, in __aenter__
        await self.connect()
    File "C:\Users\david\Documents\GitHub\Pybricks\bleak\bleak\__init__.py", line 471, in connect
        return await self._backend.connect(**kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        await self.get_services()
    File "C:\Users\david\Documents\GitHub\Pybricks\bleak\bleak\backends\winrt\client.py", line 574, in get_services
    File "C:\Users\david\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 418, in wait
        return await _wait(fs, timeout, return_when, loop)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\david\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 522, in _wait
        f.add_done_callback(_on_completion)
        ^^^^^^^^^^^^^^^^^^^
    AttributeError: '_bleak_winrt_Windows_Foundation.IAsyncOperation' object has no attribute 'add_done_callback'

asyncio.wait() requires an asyncio.Task or asyncio.Future, but we were
passing a WinRT IAsyncResult object. So we have to wrap it in a
coroutine and then in a task to avoid the error.
This changes the cache mode when getting services after a ServicesChanged
event in the WinRT backend. This matches the recommendation of the docs.

https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothledevice.gattserviceschanged?view=winrt-20348
The fix from #1101 causes the following when run with `python3.10 -X dev`.

    ERROR:asyncio:Exception in callback Future.set_result(<Future cance...events.py:429>, <_bleak_winrt...001C33C60B100>)
    handle: <Handle Future.set_result(<Future cance...events.py:429>, <_bleak_winrt...001C33C60B100>)>
    Traceback (most recent call last):
    File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
        self._context.run(self._callback, *self._args)
    asyncio.exceptions.InvalidStateError: invalid state
    ERROR:asyncio:Exception in callback Future.set_result(<Future cance...events.py:429>, <_bleak_winrt...001C33C60BFC0>)
    handle: <Handle Future.set_result(<Future cance...events.py:429>, <_bleak_winrt...001C33C60BFC0>)>
    Traceback (most recent call last):
    File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
        self._context.run(self._callback, *self._args)
    asyncio.exceptions.InvalidStateError: invalid state

This adds a new FutureLike wrapper to make the IAsyncOperation object
look like an asyncio.Future instead of wrapping it in a task.
When run with python3.10 -dev X, we get a warning that warn is
deprecated and we should replace it with warning.
Apparently, BlueZ will sometimes request to remove properties that
were not set in the first place.

Fixes: #1107
@dlech dlech merged commit f3a66f8 into master Nov 6, 2022
@dlech dlech deleted the release/0.19.2 branch November 6, 2022 21:20
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.

None yet

1 participant