<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python 'with' context manager and rest apis multi threading in ONTAP Rest API Discussions</title>
    <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/449376#M628</link>
    <description>&lt;P&gt;Without reopening the issue as such, I will just piggyback on it with another kind request for the python client library documentation authors to...&lt;BR /&gt;&lt;BR /&gt;- consider including the functional examples of `set_connection()` and other direct use of the connection variable within objects&lt;BR /&gt;- remove any mention of config.CONNECTION&lt;BR /&gt;&lt;BR /&gt;Currently, all examples are using `config.CONNECTION` which may be dangerous if end users take those examples&amp;nbsp; for granted (and they just might, given there is no other example)&amp;nbsp; and use it in their production environments, again introducing the global variable and again potentially messing with their multithreaded attempts.&lt;BR /&gt;&lt;BR /&gt;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...&lt;/P&gt;</description>
    <pubDate>Fri, 01 Dec 2023 08:17:25 GMT</pubDate>
    <dc:creator>RobertSimac</dc:creator>
    <dc:date>2023-12-01T08:17:25Z</dc:date>
    <item>
      <title>Python 'with' context manager and rest apis multi threading</title>
      <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/442026#M468</link>
      <description>&lt;P&gt;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...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If other thread executes the same 'with host_connection:' statement against other host, it may disturb whatever the first thread is doing within its'&amp;nbsp; 'with restconn:' scope...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 09:52:21 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/442026#M468</guid>
      <dc:creator>RobertSimac</dc:creator>
      <dc:date>2025-06-04T09:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python 'with' context manager and rest apis multi threading</title>
      <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/445232#M541</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.netapp.com/t5/user/viewprofilepage/user-id/56476"&gt;@RobertSimac&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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 -&amp;nbsp;&lt;A href="https://netappdiscord.com/" target="_blank"&gt;https://netappdiscord.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 01:24:20 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/445232#M541</guid>
      <dc:creator>RossC</dc:creator>
      <dc:date>2023-06-14T01:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python 'with' context manager and rest apis multi threading</title>
      <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/445249#M544</link>
      <description>&lt;P&gt;Ross thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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: &lt;A href="https://pypi.org/project/netapp-ontap/9.12.1.0rc1/" target="_blank"&gt;https://pypi.org/project/netapp-ontap/9.12.1.0rc1/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;stating the following, under the Host connections chapter:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Use the connection object as a context manager with the &lt;STRONG&gt;with&lt;/STRONG&gt; keyword. Note: This method is not recommended if you are using mutiple threads connecting to different hosts. This &lt;A href="https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/442026/highlight/true#M468" target="_blank"&gt;issue&lt;/A&gt; is currently being worked on and should be fixed in future releases."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 14:15:03 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/445249#M544</guid>
      <dc:creator>RobertSimac</dc:creator>
      <dc:date>2023-06-14T14:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python 'with' context manager and rest apis multi threading</title>
      <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/449376#M628</link>
      <description>&lt;P&gt;Without reopening the issue as such, I will just piggyback on it with another kind request for the python client library documentation authors to...&lt;BR /&gt;&lt;BR /&gt;- consider including the functional examples of `set_connection()` and other direct use of the connection variable within objects&lt;BR /&gt;- remove any mention of config.CONNECTION&lt;BR /&gt;&lt;BR /&gt;Currently, all examples are using `config.CONNECTION` which may be dangerous if end users take those examples&amp;nbsp; for granted (and they just might, given there is no other example)&amp;nbsp; and use it in their production environments, again introducing the global variable and again potentially messing with their multithreaded attempts.&lt;BR /&gt;&lt;BR /&gt;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...&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 08:17:25 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/Python-with-context-manager-and-rest-apis-multi-threading/m-p/449376#M628</guid>
      <dc:creator>RobertSimac</dc:creator>
      <dc:date>2023-12-01T08:17:25Z</dc:date>
    </item>
  </channel>
</rss>

