mirror of
https://github.com/naruxde/revpimodio2.git
synced 2025-11-08 13:53:53 +01:00
refactor: Show deprecation warning on root context manager
This context manager can delete the entire instance of ModIO when using `with rpi:` after creating an instance of ModIO by `rpi = revpimodio.RevPiModIO(...)`.
This commit is contained in:
@@ -208,6 +208,19 @@ class RevPiModIO(object):
|
||||
self._myfh.close()
|
||||
|
||||
def __enter__(self):
|
||||
# todo: Remove this context manager in future
|
||||
warnings.warn(
|
||||
"This context manager is deprecated and will be removed!\n\n"
|
||||
"You should use the context manager of the IO object `with revpi.io:` "
|
||||
"or with a single device `with revpi.device.my_device:`.\n\n"
|
||||
"This deprecated context manager can be reproduced as follows:\n"
|
||||
"```"
|
||||
"revpi = revpimodio2.RevPiModIO()"
|
||||
"with revpi.io:"
|
||||
" ..."
|
||||
"```",
|
||||
DeprecationWarning,
|
||||
)
|
||||
if self._context_manager:
|
||||
raise RuntimeError("can not use multiple context managers of same instance")
|
||||
if self._looprunning:
|
||||
|
||||
Reference in New Issue
Block a user