Re: [External] : callTimeout takes no effect (cx_Oracle 8.1; Oracle client 18.3)

Christopher Jones <[email protected]> Fri, 23 Apr 2021 08:50:23 +1000
Newsgroups gmane.comp.python.db.cx-oracle
Message-ID <[email protected]>
--===============0231904273205020915==
Content-Type: multipart/alternative;
 boundary="------------4144BFB680413ED2F962D24E"
Content-Language: en-US

--------------4144BFB680413ED2F962D24E
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit


On 23/4/21 8:44 am, ConcreteVitamin wrote:
> Hi,
>
> I'm using the following script, modified from samples/CallTimeout.py (changing into cx_Oracle.connect(mode=cx_Oracle.SYSDBA) & using a 500ms 
> timeout), and *callTimeout is not taking effects*:
>
>     import cx_Oracle
>     print(cx_Oracle.version, cx_Oracle.clientversion())
>
>     connection = cx_Oracle.connect(mode=cx_Oracle.SYSDBA)
>
>     connection.callTimeout = 500
>     print("Call timeout set at", connection.callTimeout, "milliseconds...")
>
>     cursor = connection.cursor()
>     cursor.execute("select sysdate from dual")
>     today, = cursor.fetchone()
>     print("Fetch of current date before timeout:", today)
>
>     # dbms_session.sleep() replaces dbms_lock.sleep() from Oracle Database 18c
>     sleep_proc_name = "dbms_session.sleep" \
>             if int(connection.version.split(".")[0]) >= 18 \
>             else "dbms_lock.sleep"
>
>     print("Sleeping...should time out...")
>     try:
>     cursor.callproc(sleep_proc_name, (3,))
>     except cx_Oracle.DatabaseError as e:
>         print("ERROR:", e)
>
>     cursor.execute("select sysdate from dual")
>     today, = cursor.fetchone()
>     print("Fetch of current date after timeout:", today)
>
>
> The output is:
>
>     $ python test.py
>     8.1.0 (18, 3, 0, 0, 0)
>     Call timeout set at 500 milliseconds...
>     Fetch of current date before timeout: 2021-04-22 22:39:30
>     Sleeping...should time out...
>     Fetch of current date after timeout: 2021-04-22 22:39:33
>
>
> Note that (from the output), I'm using *cx_Oracle 8.1 and Oracle client library 18.3* --- both satisfy this feature's requirements.  The DB is 
> freshly installed on an Oracle Linux box.
>
> Is there a pointer on how to resolve this? *Is it possible something about connect(mode=cx_Oracle.SYSDBA) made the timeout a no-op? *Or, should I 
> upgrade to Oracle 19 and retry?
>
Start by setting disable_oob=on in a sqlnet.ora file on your Python machine. The OOB setting is a common gotcha. See 
https://cx-oracle.readthedocs.io/en/latest/user_guide/initialization.html#optional-oracle-client-configuration-files

Or upgrade to 19c Oracle client libraries, which auto-detect the necessary OOB setting.

-- 
https://twitter.com/ghrd


--------------4144BFB680413ED2F962D24E
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 23/4/21 8:44 am, ConcreteVitamin
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAG2+eojPdMYX3wj8PtT6UhtjvqXDbXtgDJEGZoTi7Mass4KVpA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org">
      
      <div dir="ltr">Hi,
        <div><br>
        </div>
        <div>I'm using the following script, modified from
          samples/CallTimeout.py (changing into
          cx_Oracle.connect(mode=cx_Oracle.SYSDBA) &amp; using a 500ms
          timeout), and <b>callTimeout is not taking effects</b>:</div>
        <div><br>
        </div>
        <blockquote style="margin:0 0 0 40px;border:none;padding:0px">
          <div><font face="monospace">import cx_Oracle</font></div>
          <div><font face="monospace">print(cx_Oracle.version,
              cx_Oracle.clientversion())</font></div>
          <div><font face="monospace"><br>
            </font></div>
          <div><font face="monospace">connection =
              cx_Oracle.connect(mode=cx_Oracle.SYSDBA)</font></div>
          <div><font face="monospace"><br>
            </font></div>
          <div><font face="monospace">connection.callTimeout = 500</font></div>
          <div><font face="monospace">print(&quot;Call timeout set at&quot;,
              connection.callTimeout, &quot;milliseconds...&quot;)</font></div>
          <div><font face="monospace"><br>
            </font></div>
          <div><font face="monospace">cursor = connection.cursor()</font></div>
          <div><font face="monospace">cursor.execute(&quot;select sysdate
              from dual&quot;)</font></div>
          <div><font face="monospace">today, = cursor.fetchone()</font></div>
          <div><font face="monospace">print(&quot;Fetch of current date
              before timeout:&quot;, today)</font></div>
          <div><font face="monospace"><br>
            </font></div>
          <div><font face="monospace"># dbms_session.sleep() replaces
              dbms_lock.sleep() from Oracle Database 18c</font></div>
          <div><font face="monospace">sleep_proc_name =
              &quot;dbms_session.sleep&quot; \</font></div>
          <div><font face="monospace">&nbsp; &nbsp; &nbsp; &nbsp; if
              int(connection.version.split(&quot;.&quot;)[0]) &gt;= 18 \</font></div>
          <div><font face="monospace">&nbsp; &nbsp; &nbsp; &nbsp; else &quot;dbms_lock.sleep&quot;</font></div>
          <div><font face="monospace"><br>
            </font></div>
          <div><font face="monospace">print(&quot;Sleeping...should time
              out...&quot;)</font></div>
          <div><font face="monospace">try:</font></div>
          <div><font face="monospace">&nbsp; &nbsp;
              cursor.callproc(sleep_proc_name, (3,))</font></div>
          <div><font face="monospace">except cx_Oracle.DatabaseError as
              e:</font></div>
          <div><font face="monospace">&nbsp; &nbsp; print(&quot;ERROR:&quot;, e)</font></div>
          <div><font face="monospace"><br>
            </font></div>
          <div><font face="monospace">cursor.execute(&quot;select sysdate
              from dual&quot;)</font></div>
          <div><font face="monospace">today, = cursor.fetchone()</font></div>
          <div><font face="monospace">print(&quot;Fetch of current date after
              timeout:&quot;, today)</font></div>
        </blockquote>
        <div><br>
        </div>
        <div>The output is:</div>
        <div><br>
        </div>
        <blockquote style="margin:0 0 0 40px;border:none;padding:0px">
          <div><font face="monospace">$ python test.py</font></div>
          <div><font face="monospace">8.1.0 (18, 3, 0, 0, 0)</font></div>
          <div><font face="monospace">Call timeout set at 500
              milliseconds...</font></div>
          <div><font face="monospace">Fetch of current date before
              timeout: 2021-04-22 22:39:30</font></div>
          <div><font face="monospace">Sleeping...should time out...</font></div>
          <div><font face="monospace">Fetch of current date after
              timeout: 2021-04-22 22:39:33</font></div>
        </blockquote>
        <div><br>
        </div>
        <div>Note that (from the output), I'm using <b>cx_Oracle 8.1
            and Oracle client library 18.3</b> --- both satisfy this
          feature's&nbsp;requirements.&nbsp; The DB is freshly installed on an
          Oracle Linux box.</div>
        <div><br>
        </div>
        <div>Is there a pointer on how to resolve this?&nbsp; <b>Is it
            possible something about&nbsp;connect(mode=cx_Oracle.SYSDBA) made
            the timeout a no-op?&nbsp; </b>Or, should I upgrade to Oracle 19
          and retry?</div>
        <div><br>
        </div>
      </div>
    </blockquote>
    <p>Start by setting <font face="monospace">disable_oob=on</font> in
      a sqlnet.ora file on your Python machine. The OOB setting is a
      common gotcha. See
<a class="moz-txt-link-freetext" href="https://cx-oracle.readthedocs.io/en/latest/user_guide/initialization.html#optional-oracle-client-configuration-files">https://cx-oracle.readthedocs.io/en/latest/user_guide/initialization.html#optional-oracle-client-configuration-files</a></p>
    <p> Or upgrade to 19c Oracle client libraries, which auto-detect the
      necessary OOB setting.<br>
    </p>
    <pre class="moz-signature" cols="150">-- 
<a class="moz-txt-link-freetext" href="https://twitter.com/ghrd">https://twitter.com/ghrd</a>
</pre>
  </body>
</html>

--------------4144BFB680413ED2F962D24E--


--===============0231904273205020915==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============0231904273205020915==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
cx-oracle-users mailing list
cx-oracle-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/cx-oracle-users

--===============0231904273205020915==--