<div dir="auto">Robert sorry for the delay. What could be useful if you can produce chunk of python routing code (could be NOP on the functional side) that crashes repeatedly on our voiptest jig (<a href="https://github.com/sippy/voiptests">https://github.com/sippy/voiptests</a>). The travis is setup to build pull requests, so that you can inject your code and let it rip. It uses similar configiration of linux / python. <div dir="auto"><br></div><div dir="auto">-Max</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Apr 21, 2017 9:32 AM, "Mundkowsky, Robert" <<a href="mailto:rmundkowsky@ets.org" target="_blank">rmundkowsky@ets.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_7329958631548415217WordSection1">
<p class="MsoNormal"><a name="m_7329958631548415217__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Python 2.7.13  on Ubuntu 16.04.2 LTS.<u></u><u></u></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">How do you link using pthreads?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-indent:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Do you add flags to Makefile, or will setting “USE_PTHREAD_MUTEX” and “USE_POSIX_SEM” via menuconfig do it?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Since openSIPS is not multithread, seems like it would be a lot cleaner to not use threads at all on C/C++.  Then threads could still be used on Python side if
 needed.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Robert Mundkowsky<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Maxim Sobolev [mailto:<a href="mailto:sobomax@sippysoft.com" target="_blank">sobomax@sippysoft.com</a>]
<br>
<b>Sent:</b> Friday, April 21, 2017 11:57 AM<br>
<b>To:</b> Bogdan-Andrei Iancu <<a href="mailto:bogdan@opensips.org" target="_blank">bogdan@opensips.org</a>><br>
<b>Cc:</b> OpenSIPS users mailling list <<a href="mailto:users@lists.opensips.org" target="_blank">users@lists.opensips.org</a>>; Mundkowsky, Robert <<a href="mailto:rmundkowsky@ets.org" target="_blank">rmundkowsky@ets.org</a>><br>
<b>Subject:</b> Re: [OpenSIPS-Users] python module - bug and questions<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">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.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">-Max<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Fri, Apr 21, 2017 at 1:25 AM, Bogdan-Andrei Iancu <<a href="mailto:bogdan@opensips.org" target="_blank">bogdan@opensips.org</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal"><tt><span style="font-size:10.0pt">Hi Robert,</span></tt><span style="font-size:10.0pt;font-family:"Courier New""><br>
<br>
<tt>The only question I can answer is 1) - OpenSIPS it is a multi-process application (and not using threads).
</tt><br>
<br>
<tt>How the python module is design (from threading perspective), I do not know - maybe Maxim, the author of this module can help with this.</tt><br>
<br>
<tt>Regards,</tt><br>
<br>
</span><u></u><u></u></p>
<pre>Bogdan-Andrei Iancu<u></u><u></u></pre>
<pre>  OpenSIPS Founder and Developer<u></u><u></u></pre>
<pre>  <a href="http://www.opensips-solutions.com" target="_blank">http://www.opensips-solutions.<wbr>com</a><u></u><u></u></pre>
<pre><u></u> <u></u></pre>
<pre>OpenSIPS Summit May 2017 Amsterdam<u></u><u></u></pre>
<pre>  <a href="http://www.opensips.org/events/Summit-2017Amsterdam.html" target="_blank">http://www.opensips.org/<wbr>events/Summit-2017Amsterdam.<wbr>html</a><u></u><u></u></pre>
<div>
<div>
<div>
<p class="MsoNormal">On 04/19/2017 08:43 PM, Mundkowsky, Robert wrote:<u></u><u></u></p>
</div>
</div>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<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_7329958631548415217m-2679145434075060159msolistparagraph">1)<span style="font-size:7.0pt">     
</span>I am guessing that OpenSIPS uses a multi-threaded architecture?<u></u><u></u></p>
<p class="m_7329958631548415217m-2679145434075060159msolistparagraph">2)<span style="font-size:7.0pt">     
</span>Is the python module meant to be a single thread? Or multi-threaded?<u></u><u></u></p>
<p class="m_7329958631548415217m-2679145434075060159msolistparagraph" style="margin-left:1.0in">a.<span style="font-size:7.0pt">      
</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_7329958631548415217m-2679145434075060159msolistparagraph" style="margin-left:1.0in"><span class="m_7329958631548415217m-2679145434075060159pl-c1">b.</span><span class="m_7329958631548415217m-2679145434075060159pl-c1"><span style="font-size:7.0pt">     
</span></span>If it is meant to be multi-threaded then why is there only one call to
<span class="m_7329958631548415217m-2679145434075060159pl-c1">PyThreadState_New and </span>myThreadState is a global used everywhere?<u></u><u></u></p>
<p class="m_7329958631548415217m-2679145434075060159msolistparagraph" style="margin-left:1.5in"><span style="font-size:7.0pt">                              <wbr>                              <wbr>  
</span>i.      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_7329958631548415217m-2679145434075060159msolistparagraph">3)<span style="font-size:7.0pt">     
</span>Also why is there no clean up code (PyThreadState_Clear, PyThreadState_Delete, Py_Finalize)?<u></u><u></u></p>
<p class="m_7329958631548415217m-2679145434075060159msolistparagraph" style="margin-left:1.0in">a.<span style="font-size:7.0pt">      
</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">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">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">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>
<p class="MsoNormal"><u></u> <u></u></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="100%" align="center">
</div>
<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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p>Thank you for your compliance.<u></u><u></u></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="100%" align="center">
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p>
</div>
</div>
<pre>______________________________<wbr>_________________<u></u><u></u></pre>
<pre>Users mailing list<u></u><u></u></pre>
<pre><a href="mailto:Users@lists.opensips.org" target="_blank">Users@lists.opensips.org</a><u></u><u></u></pre>
<pre><a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-<wbr>bin/mailman/listinfo/users</a><u></u><u></u></pre>
</blockquote>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">Maksym Sobolyev<br>
Sippy Software, Inc.<br>
Internet Telephony (VoIP) Experts<br>
Tel (Canada): <a href="tel:(778)%20783-0474" value="+17787830474" target="_blank">+1-778-783-0474</a><br>
Tel (Toll-Free): <a href="tel:(855)%20747-7779" value="+18557477779" target="_blank">+1-855-747-7779</a><br>
Fax: <a href="tel:(866)%20857-6942" value="+18668576942" target="_blank">+1-866-857-6942</a><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<u></u><u></u></p>
</div>
</div>
</div>
</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>
</div>

</blockquote></div></div>