<div dir="ltr">Robert, what Bogdan says is essentially correct. The OpenSIPS itself is not using any threads AFAIK, therefore python module code is kept as simple as possible. Now back to the original question: we use quite a lot of python code in our routing and some of the python modules that are running are actually creating threads on their own and it appears to be pretty stable. What OS / python version are you using? What could be different in our case is that we link our OpenSIPS binary with pthreads always (which may or may not be the case on your build), so there might be some vital threads runtime infrastructure that is not getting initialized in your case.<div><br></div><div>-Max</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 21, 2017 at 1:25 AM, Bogdan-Andrei Iancu <span dir="ltr"><<a href="mailto:bogdan@opensips.org" target="_blank">bogdan@opensips.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<tt>Hi Robert,<br>
<br>
The only question I can answer is 1) - OpenSIPS it is a
multi-process application (and not using threads). <br>
<br>
How the python module is design (from threading perspective), I do
not know - maybe Maxim, the author of this module can help with
this.<br>
<br>
Regards,<br>
</tt>
<pre class="m_-2679145434075060159moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="m_-2679145434075060159moz-txt-link-freetext" href="http://www.opensips-solutions.com" target="_blank">http://www.opensips-solutions.<wbr>com</a>
OpenSIPS Summit May 2017 Amsterdam
<a class="m_-2679145434075060159moz-txt-link-freetext" href="http://www.opensips.org/events/Summit-2017Amsterdam.html" target="_blank">http://www.opensips.org/<wbr>events/Summit-2017Amsterdam.<wbr>html</a>
</pre><div><div class="h5">
<div class="m_-2679145434075060159moz-cite-prefix">On 04/19/2017 08:43 PM, Mundkowsky,
Robert wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div class="m_-2679145434075060159WordSection1">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">This email should likely go to your other
dev forum, but I don’t have access yet.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am using openSIPS 2.2.3 on Ubuntu 16.04.2
LTS. <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am using the python module. The python
script called works fine when called from outside openSIPS and
it works fine when called inside openSIPS, if it is triggered
once at a time.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">But if the python script is triggered twice
by two phone calls or more or even one call after another in
short order, then there are weird errors which show up in
different places in the code like:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="text-indent:.5in">ERROR:python:python_handle_<wbr>exception:
#011TypeError: an integer is required<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am guessing the openSIP python module has
some problem/s related to threading.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="text-indent:.5in"><u></u> <u></u></p>
<p class="MsoNormal">Questions:<u></u><u></u></p>
<p class="m_-2679145434075060159MsoListParagraph"><span>1)<span style="font:7.0pt "Times New Roman"">
</span></span>I am guessing that OpenSIPS uses
a multi-threaded architecture?<u></u><u></u></p>
<p class="m_-2679145434075060159MsoListParagraph"><span>2)<span style="font:7.0pt "Times New Roman"">
</span></span>Is the python module meant to be
a single thread? Or multi-threaded?<u></u><u></u></p>
<p class="m_-2679145434075060159MsoListParagraph" style="margin-left:1.0in">
<span>a.<span style="font:7.0pt "Times New Roman"">
</span></span>If it is meant to be single
threaded then why use python library thread functions? Just
use python library without multi-threaded stuff.<u></u><u></u></p>
<p class="m_-2679145434075060159MsoListParagraph" style="margin-left:1.0in">
<span class="m_-2679145434075060159pl-c1"><span>b.<span style="font:7.0pt "Times New Roman"">
</span></span></span>If it is meant to be
multi-threaded then why is there only one call to
<span class="m_-2679145434075060159pl-c1">PyThreadState_New and </span>myThreadState
is a global used everywhere?<span class="m_-2679145434075060159pl-c1"><u></u><u></u></span></p>
<p class="m_-2679145434075060159MsoListParagraph" style="margin-left:1.5in">
<span><span style="font:7.0pt "Times New Roman""> <wbr> <wbr>
</span>i.<span> </span></span>I would
think a thread per call to python_exec would make more sense
and make the code easier to understand?<u></u><u></u></p>
<p class="m_-2679145434075060159MsoListParagraph"><span>3)<span style="font:7.0pt "Times New Roman"">
</span></span>Also why is there no clean up
code (PyThreadState_Clear, PyThreadState_Delete, Py_Finalize)?<u></u><u></u></p>
<p class="m_-2679145434075060159MsoListParagraph" style="margin-left:1.0in">
<span>a.<span style="font:7.0pt "Times New Roman"">
</span></span>I am guessing the idea is you do
not need clean up, because it only happens when openSIPS is
turned off.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Robert<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">For reference:<u></u><u></u></p>
<p class="MsoNormal" style="text-indent:.5in"><a href="https://www.codeproject.com/articles/11805/embedding-python-in-c-c-part-i" target="_blank"></a><a class="m_-2679145434075060159moz-txt-link-freetext" href="https://www.codeproject.com/articles/11805/embedding-python-in-c-c-part-i" target="_blank">https://www.codeproject.com/<wbr>articles/11805/embedding-<wbr>python-in-c-c-part-i</a><u></u><u></u></p>
<p class="MsoNormal" style="text-indent:.5in"><a href="http://www.awasu.com/weblog/embedding-python/threads/" target="_blank"></a><a class="m_-2679145434075060159moz-txt-link-freetext" href="http://www.awasu.com/weblog/embedding-python/threads/" target="_blank">http://www.awasu.com/weblog/<wbr>embedding-python/threads/</a><u></u><u></u></p>
<p class="MsoNormal" style="text-indent:.5in"><a href="http://stackoverflow.com/questions/26061298/python-multi-thread-multi-interpreter-c-api" target="_blank"></a><a class="m_-2679145434075060159moz-txt-link-freetext" href="http://stackoverflow.com/questions/26061298/python-multi-thread-multi-interpreter-c-api" target="_blank">http://stackoverflow.com/<wbr>questions/26061298/python-<wbr>multi-thread-multi-<wbr>interpreter-c-api</a><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<br>
<hr>
<p>This e-mail and any files transmitted with it may contain
privileged or confidential information. It is solely for use by
the individual for whom it is intended, even if addressed
incorrectly. If you received this e-mail in error, please notify
the sender; do not disclose, copy, distribute, or take any
action in reliance on the contents of this information; and
delete it from your system. Any other use of this e-mail is
prohibited.</p>
<br>
<p>Thank you for your compliance.</p>
<hr>
<br>
<fieldset class="m_-2679145434075060159mimeAttachmentHeader"></fieldset>
<br>
</div></div><pre>______________________________<wbr>_________________
Users mailing list
<a class="m_-2679145434075060159moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org" target="_blank">Users@lists.opensips.org</a>
<a class="m_-2679145434075060159moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-<wbr>bin/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Maksym Sobolyev<br>Sippy Software, Inc.<br>Internet Telephony (VoIP) Experts<br>Tel (Canada): +1-778-783-0474<br>Tel (Toll-Free): +1-855-747-7779<br>Fax: +1-866-857-6942<br>Web: <a href="http://www.sippysoft.com" target="_blank">http://www.sippysoft.com</a><br>MSN: <a href="mailto:sales@sippysoft.com" target="_blank">sales@sippysoft.com</a><br>Skype: SippySoft<br></div></div>
</div>