-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Python] Convert async API functions to python asyncio #33989
[Python] Convert async API functions to python asyncio #33989
Conversation
PR #33989: Size comparison from acf823f to 4925772 Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
4925772
to
5051453
Compare
5051453
to
a481baa
Compare
PR #33989: Size comparison from bec5fc3 to a481baa Full report (8 builds for cc32xx, mbed, qpg, stm32, tizen)
|
a481baa
to
d23759e
Compare
PR #33989: Size comparison from bec5fc3 to d23759e Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
d23759e
to
64f79f6
Compare
PR #33989: Size comparison from f6ac926 to 64f79f6 Full report (49 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, tizen)
|
64f79f6
to
1e0aadc
Compare
PR #33989: Size comparison from f6ac926 to 1e0aadc Full report (49 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, tizen)
|
1e0aadc
to
dc04fc2
Compare
PR #33989: Size comparison from f6ac926 to dc04fc2 Full report (49 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, tizen)
|
Use a context manager to handle the commissioning process in the device controller. This will ensure that the commissioning resources are properly cleaned up after completion and removes boiler plate code. Also clear fabricCheckNodeId and mark it internal use by adding the underline prefix. Also call pychip_ScriptDevicePairingDelegate_SetExpectingPairingComplete directly on the Python Thread, as this is an atomic operation. This is will also be more asyncio friendly as it is guaranteed to not block.
Use context managers for all APIs which wait for callbacks. This allows to cleanly wrap the future and add additional handling e.g. locks for asyncio in the future.
Make all commissioning APIs async functions. This avoids the need to use run_in_executor() to call them from asyncio code in a non- blocking way.
Make sure that different asyncio tasks do not run the same function concurrently. This is done by adding an asyncio lock to functions which use callbacks.
907e2bf
to
61d0b1b
Compare
PR #33989: Size comparison from 38f664f to 864519d Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
PR #33989: Size comparison from 38f664f to b29e0cf Increases above 0.2%:
Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
This adds commissioning API updates from the master branch to our 1.3 based branch. This makes the commissioning API more Pythonic and allows to call them from the asyncio event loop directly. Specifically, this integrates changes from the following PRs - project-chip/connectedhomeip#33954 - project-chip/connectedhomeip#33905 - project-chip/connectedhomeip#34011 - project-chip/connectedhomeip#34001 - project-chip/connectedhomeip#33989
This adds commissioning API updates from the master branch to our 1.3 based branch. This makes the commissioning API more Pythonic and allows to call them from the asyncio event loop directly. Specifically, this integrates changes from the following PRs - project-chip/connectedhomeip#33954 - project-chip/connectedhomeip#33905 - project-chip/connectedhomeip#34001 - project-chip/connectedhomeip#33989
…33989) * [Python] Use context manager for Commissioning Use a context manager to handle the commissioning process in the device controller. This will ensure that the commissioning resources are properly cleaned up after completion and removes boiler plate code. Also clear fabricCheckNodeId and mark it internal use by adding the underline prefix. Also call pychip_ScriptDevicePairingDelegate_SetExpectingPairingComplete directly on the Python Thread, as this is an atomic operation. This is will also be more asyncio friendly as it is guaranteed to not block. * [Python] Use context manager for all callbacks Use context managers for all APIs which wait for callbacks. This allows to cleanly wrap the future and add additional handling e.g. locks for asyncio in the future. * [Python] Convert commissioning APIs to async functions Make all commissioning APIs async functions. This avoids the need to use run_in_executor() to call them from asyncio code in a non- blocking way. * [Python] Convert UnpairDevice/OpenCommissioningWindow to asyncio * [Python] Convert EstablishPASESession to asyncio * [Python] Convert IssueNOCChain to asyncio * [Python] Add locking to prevent concurrent access with asyncio Make sure that different asyncio tasks do not run the same function concurrently. This is done by adding an asyncio lock to functions which use callbacks. * [Python] Raise an exception if the future did not complete * [Python] Convert tests in src/controller/python/ to asyncio * [Python] Convert tests in src/python_testing/ to asyncio * Adjust yamltest_with_chip_repl_tester to use asyncio * [Python] Add documentation to the new context managers * [Python] Use asyncio.run() to run async tests
Convert API functions which are waiting for a callback to Python co-routines (async functions). This allows to use this API functions without blocking the asyncio event loop, which is crucial for a responsive asyncio application.
The change takes care of locking the individual functions so that independent asyncio tasks can't interfere with each other: E.g. if two asyncio tasks try to commission a device, the second asyncio task trying to commission too will wait for the first asyncio task to complete commission first.