ONTAP Rest API Discussions
ONTAP Rest API Discussions
I do have slight suspicion, based on some observed problems, the ontap rest api python recommended use of 'with host_connection:' may run into problems when called from two separate threads, against two separate hosts...
Namely, there is an 'global _HOST_CONTEXT_' variable set right at the HostConnection.__enter__() method, which re-sets the global host context for the 'duration' of such 'with' context. (netapp_ontap\host_connection.py)
If other thread executes the same 'with host_connection:' statement against other host, it may disturb whatever the first thread is doing within its' 'with restconn:' scope...
I was not able to find anything in current documentation regarding multi threading, thus the question here if anyone experienced any issues in that area.
thanks
Solved! See The Solution
Ross thanks for the reply.
In the meantime my original concern was confirmed and the bug (burt) was opened against the Ontap REST API Python client library and the problem is acknowledged in its latest release: https://pypi.org/project/netapp-ontap/9.12.1.0rc1/
stating the following, under the Host connections chapter:
"Use the connection object as a context manager with the with keyword. Note: This method is not recommended if you are using mutiple threads connecting to different hosts. This issue is currently being worked on and should be fixed in future releases."
In short, do not use `with host_connection` syntax if using api from multiple threads. The .set_connection() method is available for all objects and is very easy , convenient and safe to use instead.
Hi @RobertSimac
Sorry that no one from the community was able to help you with this query so far. We have an active #ontap-api channel in our NetApp Community Discord, so you may want to consider jumping onto that and asking your query there. To jump onto our Community Discord head to - https://netappdiscord.com/
Hope this helps.
Ross thanks for the reply.
In the meantime my original concern was confirmed and the bug (burt) was opened against the Ontap REST API Python client library and the problem is acknowledged in its latest release: https://pypi.org/project/netapp-ontap/9.12.1.0rc1/
stating the following, under the Host connections chapter:
"Use the connection object as a context manager with the with keyword. Note: This method is not recommended if you are using mutiple threads connecting to different hosts. This issue is currently being worked on and should be fixed in future releases."
In short, do not use `with host_connection` syntax if using api from multiple threads. The .set_connection() method is available for all objects and is very easy , convenient and safe to use instead.
Without reopening the issue as such, I will just piggyback on it with another kind request for the python client library documentation authors to...
- consider including the functional examples of `set_connection()` and other direct use of the connection variable within objects
- remove any mention of config.CONNECTION
Currently, all examples are using `config.CONNECTION` which may be dangerous if end users take those examples for granted (and they just might, given there is no other example) and use it in their production environments, again introducing the global variable and again potentially messing with their multithreaded attempts.
I think it would be beneficial for all to convert all examples to plain and simple `set_connection()` using the local variables. That way, there is no danger the verbatim sample use will cause trouble in production...