Skip to content

Commit

Permalink
[Python] Drop network lock
Browse files Browse the repository at this point in the history
The network lock is not needed in the Python controller, as all calls
to the SDK are made by posting to the Matter SDK event loop through
ScheduleWork(), hence are guaranteed to be serialized.

From how I understand ScheduleWork() works, it pushes the work to the
event loop through PostEvent() which at least on POSIX is using the
thread safe device queue (see GenericPlatformManagerImpl_POSIX.cpp).
  • Loading branch information
agners committed Jun 4, 2024
1 parent 44526d2 commit 3f8deab
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/controller/python/chip/ChipStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ class ChipStack(object):
def __init__(self, persistentStoragePath: str, enableServerInteractions=True):
builtins.enableDebugMode = False

# TODO: Probably no longer necessary, see https://github.com/project-chip/connectedhomeip/issues/33321.
self.networkLock = Lock()
self.completeEvent = Event()
self.commissioningCompleteEvent = Event()
self._ChipStackLib = None
Expand Down Expand Up @@ -212,7 +210,6 @@ def Shutdown(self):
# #20437 tracks consolidating these.
#
self._ChipStackLib.pychip_CommonStackShutdown()
self.networkLock = None
self.completeEvent = None
self._ChipStackLib = None
self._chipDLLPath = None
Expand All @@ -226,10 +223,7 @@ def Call(self, callFunct, timeoutMs: int = None):
This function is a wrapper of PostTaskOnChipThread, which includes some handling of application specific logics.
Calling this function on CHIP on CHIP mainloop thread will cause deadlock.
'''
# TODO: Lock probably no longer necessary, see https://github.com/project-chip/connectedhomeip/issues/33321.
with self.networkLock:
res = self.PostTaskOnChipThread(callFunct).Wait(timeoutMs)
return res
return self.PostTaskOnChipThread(callFunct).Wait(timeoutMs)

async def CallAsync(self, callFunct, timeoutMs: int = None):
'''Run a Python function on CHIP stack, and wait for the response.
Expand All @@ -256,9 +250,7 @@ def CallAsyncWithCompleteCallback(self, callFunct):
# throw error if op in progress
self.callbackRes = None
self.completeEvent.clear()
# TODO: Lock probably no longer necessary, see https://github.com/project-chip/connectedhomeip/issues/33321.
with self.networkLock:
res = self.PostTaskOnChipThread(callFunct).Wait()
res = self.PostTaskOnChipThread(callFunct).Wait()

if not res.is_success:
self.completeEvent.set()
Expand Down

0 comments on commit 3f8deab

Please sign in to comment.