<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hello,</p>
<p>then you do not use the KEMI framework as config interpreter, but
native configuration interpreter with inline execution of Python
code via python_exec(). KSR module is exported for both cases,
KEMI or inline execution, but KSR.x.exit() (or python exit) stops
the KEMI execution, not the native config execution.</p>
<p>A way to signal that you want to exit native config execution
after python_exec() is to use some local variable, like:</p>
<p>$var(exit) = 0;</p>
<p>python_exec(...);</p>
<p>if($var(exit) == 1) exit;</p>
<p>And inside the python script you execute with python_exec() set
$var(exit) to 1 via KSR.pv_seti(...) whenever you want to do an
exit.</p>
<p>Otherwise, I haven't developed python_exec() to see what exactly
it does and if it propagates return 0 from python script to
kamailio native interpreter -- return code 0 is used to signal a
stop of config execution, done from a sub-route or a c function:</p>
<p> * <a class="moz-txt-link-freetext" href="https://www.kamailio.org/wiki/cookbooks/devel/core#return">https://www.kamailio.org/wiki/cookbooks/devel/core#return</a><br>
</p>
Cheers,<br>
Daniel<br>
<br>
<div class="moz-cite-prefix">On 29.03.18 10:13, Enrico Bandiera
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAGqwm+dC=SuusNv27Za+B0Sr7n6Jjq21tO7yr0RRStz1pjFQrg@mail.gmail.com">
<div dir="ltr">Hi Daniel,
<div><br>
</div>
<div>it seems that your suggestion is not working, we are not
using python for the whole script, we have some functions
written in python to manipulate jsons and to do API queries
which we keep in python but the core of the routing logic is
still written in Kamailio scripting language.</div>
<div><br>
</div>
<div>We call the python functions with python_exec()</div>
<div><br>
</div>
<div>I tried to use both exit() and os.exit() but it looks like
they are ignored and the route execution continues, the only
thing that seems to work is to return 0 from the function</div>
<div><br>
</div>
<div>Can you tell me please if it is safe to use the return
value to exit?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Enrico.</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">2018-03-28 16:35 GMT+02:00
Daniel-Constantin Mierla <span dir="ltr"><<a
href="mailto:miconda@gmail.com" target="_blank"
moz-do-not-send="true">miconda@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>Hello,</p>
<p>in Python you can call exit() or os.exit(), this throws
an exception which is caught by Kamailio and interpreted
as the usual exit from kamailio.cfg.</p>
<p>Probably we should add the KSR.x.exit() there as well,
it was not added because python exit gave what was
needed in this case</p>
<p>Cheers,<br>
Daniel<br>
</p>
<div>
<div class="h5"> <br>
<div class="m_6995966612575938142moz-cite-prefix">On
27.03.18 16:49, Enrico Bandiera wrote:<br>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div class="h5">
<div dir="ltr">Hello, I'm trying to use the
KSR.x.exit() function in a KEMI python script but
at runtime i get this error:
<div><br>
</div>
<div>
<div>KSR.x.exit()</div>
<div>AttributeError: 'module' object has no
attribute 'exit'</div>
</div>
<div><br>
</div>
<div>It seems that the exit function is
missing even though it is documented.</div>
<div><br>
</div>
<div>My kamailio version is: kamailio 5.2.0-dev4
(x86_64/linux) (it's a nightly)</div>
<div><br>
</div>
<div>Any idea on what I can do?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Enrico.</div>
</div>
<br>
<fieldset
class="m_6995966612575938142mimeAttachmentHeader"></fieldset>
<br>
</div>
</div>
<pre>______________________________<wbr>_________________
Kamailio (SER) - Users Mailing List
<a class="m_6995966612575938142moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a>
<a class="m_6995966612575938142moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/<wbr>cgi-bin/mailman/listinfo/sr-<wbr>users</a><span class="HOEnZb"><font color="#888888">
</font></span></pre>
<span class="HOEnZb"><font color="#888888"> </font></span></blockquote>
<span class="HOEnZb"><font color="#888888"> <br>
<pre class="m_6995966612575938142moz-signature" cols="72">--
Daniel-Constantin Mierla
<a class="m_6995966612575938142moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" target="_blank" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a class="m_6995966612575938142moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" target="_blank" moz-do-not-send="true">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - April 16-18, 2018, Berlin - <a class="m_6995966612575938142moz-txt-link-abbreviated" href="http://www.asipto.com" target="_blank" moz-do-not-send="true">www.asipto.com</a>
Kamailio World Conference - May 14-16, 2018 - <a class="m_6995966612575938142moz-txt-link-abbreviated" href="http://www.kamailioworld.com" target="_blank" moz-do-not-send="true">www.kamailioworld.com</a></pre>
</font></span></div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Daniel-Constantin Mierla
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - April 16-18, 2018, Berlin - <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
Kamailio World Conference - May 14-16, 2018 - <a class="moz-txt-link-abbreviated" href="http://www.kamailioworld.com">www.kamailioworld.com</a></pre>
</body>
</html>