Skip to content

Commit 5791af4

Browse files
Fix bug with async on_update_name callbacks
This leaks even more async code into the device, but I can't see a way around it without having to require the dispatcher be provided before creating records...
1 parent 0591f51 commit 5791af4

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

softioc/device.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ def __init__(self, name, **kargs):
150150
else:
151151
self.__on_update = None
152152

153+
# We cannot simply use `iscoroutinefunction` at the point of calling
154+
# on_update as the lambda used for on_update_name is NOT a coroutine.
155+
# There's no way to examine the lambda to see if it'd return a
156+
# coroutine without calling it, so we must keep track of it ourselves.
157+
# This is an unfortunate, unavoidable, leak of implementation detail
158+
# that really should be contained in the dispatcher.
159+
self.__on_update_is_coroutine = False
160+
if (
161+
iscoroutinefunction(on_update)
162+
or iscoroutinefunction(on_update_name)
163+
):
164+
self.__on_update_is_coroutine = True
165+
153166
self.__validate = kargs.pop('validate', None)
154167
self.__always_update = kargs.pop('always_update', False)
155168
self.__enable_write = True
@@ -225,7 +238,7 @@ def _process(self, record):
225238
if self.__on_update and self.__enable_write:
226239
record.PACT = self._blocking
227240

228-
if iscoroutinefunction(self.__on_update):
241+
if self.__on_update_is_coroutine:
229242
# This is an unfortunate, but unavoidable, leak of
230243
# implementation detail that really should be kept within
231244
# the dispatcher, but cannot be. This is due to asyncio not

0 commit comments

Comments
 (0)