aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/sys_utils
diff options
context:
space:
mode:
authorLane Kolbly <lane.kolbly@ni.com>2020-03-03 13:00:20 -0600
committeratrnati <54334261+atrnati@users.noreply.github.com>2020-03-03 15:16:06 -0600
commit11bc3fa3a861d53aa387bb21d26d0d36e961fd78 (patch)
tree56852e61c2096bc9762572b38cde5aef0819fc2c /mpm/python/usrp_mpm/sys_utils
parentf73f608d9506642579773d0ba969bf96a1871f32 (diff)
downloaduhd-11bc3fa3a861d53aa387bb21d26d0d36e961fd78.tar.gz
uhd-11bc3fa3a861d53aa387bb21d26d0d36e961fd78.tar.bz2
uhd-11bc3fa3a861d53aa387bb21d26d0d36e961fd78.zip
mpm: Make contextmanagers exception-safe
When making context managers in Python, the yield statement has to be wrapped in a try/finally clause in order to properly clean up after exceptions happen.
Diffstat (limited to 'mpm/python/usrp_mpm/sys_utils')
-rw-r--r--mpm/python/usrp_mpm/sys_utils/uio.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/mpm/python/usrp_mpm/sys_utils/uio.py b/mpm/python/usrp_mpm/sys_utils/uio.py
index c724557e6..84e4b2b64 100644
--- a/mpm/python/usrp_mpm/sys_utils/uio.py
+++ b/mpm/python/usrp_mpm/sys_utils/uio.py
@@ -24,8 +24,10 @@ def open_uio(label=None, path=None, length=None, read_only=True, offset=None):
Use this like you would open() for a file"""
uio_obj = UIO(label, path, length, read_only, offset)
uio_obj._open()
- yield uio_obj
- uio_obj._close()
+ try:
+ yield uio_obj
+ finally:
+ uio_obj._close()
def get_all_uio_devs():