feat: Add context manager for modio instance

Signed-off-by: Sven Sager <akira@narux.de>
This commit is contained in:
2023-11-20 10:14:33 +01:00
parent 5a6ed54e5c
commit d5320603f5

View File

@@ -109,13 +109,18 @@ class IOList(object):
return self return self
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
""" """Write outputs to process image before leaving the context manager."""
Write outputs to process image before leaving the context manager. if self.__modio._imgwriter.is_alive():
# Reset new data flat to sync with imgwriter
self.__modio._imgwriter.newdata.clear()
If 'autorefresh=True' is used, this operation is asynchronous. The # Write outputs on devices without autorefresh
outputs are automatically written in the background.
"""
self.__modio.writeprocimg() self.__modio.writeprocimg()
if self.__modio._imgwriter.is_alive():
# Wait until imgwriter has written outputs
self.__modio._imgwriter.newdata.wait(2.5)
if self.__modio._context_manager: if self.__modio._context_manager:
# Do not reset if ModIO is in a context manager itself, it will handle that flag # Do not reset if ModIO is in a context manager itself, it will handle that flag
self.__modio._looprunning = False self.__modio._looprunning = False