From 12a34e7d11a9f58535eebb64498c3708c195778d Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Mon, 20 Nov 2023 09:04:34 +0100 Subject: [PATCH] docs: Add IO context manager description Signed-off-by: Sven Sager --- src/revpimodio2/io.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/revpimodio2/io.py b/src/revpimodio2/io.py index 4dae8bd..b77e78d 100644 --- a/src/revpimodio2/io.py +++ b/src/revpimodio2/io.py @@ -88,6 +88,17 @@ class IOList(object): io_del._parentdevice._update_my_io_list() def __enter__(self): + """ + Read inputs on entering context manager and write outputs on leaving. + + All entries are read when entering the context manager. Within the + context manager, further .readprocimg() or .writeprocimg() calls can + be made and the process image can be read or written. When exiting, + all outputs are always written into the process image. + + When 'autorefresh=True' is used, all read or write actions in the + background are performed automatically. + """ if self.__modio._looprunning: raise RuntimeError("can not start multiple mainloop/cycleloop/with sessions") self.__modio._looprunning = True @@ -96,6 +107,12 @@ class IOList(object): return self def __exit__(self, exc_type, exc_val, exc_tb): + """ + Write outputs to process image before leaving the context manager. + + If 'autorefresh=True' is used, this operation is asynchronous. The + outputs are automatically written in the background. + """ self.__modio.writeprocimg() self.__modio._looprunning = False