<div dir="ltr">Hello Daniel,<div><br></div><div>Probably, the process is not killed, because the child processes of the python module are not included in the kamailio children list.<br></div><div><br></div><div>How can I register an event route in KEMI script?</div><div><a href="https://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/kemi/#python-kemi-interpreter">Doc</a> says:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">event route callback - the name of the Python function to be executed instead of module specific event_route blocks is provided via event_callback parameter of that module</blockquote><div>but <a href="https://www.kamailio.org/docs/modules/devel/modules/evrexec.html">evrexec</a> doesn't have an event_callback parameter.</div><div><br></div><div>I tried to set up exec parameter (_update is Python function)</div><div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(0,0,255)">modparam</span>(<span style="color:rgb(163,21,21)">"evrexec"</span>, <span style="color:rgb(163,21,21)">"exec"</span>, <span style="color:rgb(163,21,21)">"name=_update;workers=1;"</span>)</div></div></div><div>and got warning</div><div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre"><div>WARNING: evrexec [evrexec_mod.c:<span style="color:rgb(9,134,88)">180</span>]: evrexec_process(): empty event route block [_update]</div></div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">ср, 14 сент. 2022 г. в 16:21, Daniel-Constantin Mierla <<a href="mailto:miconda@gmail.com">miconda@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Hello,</p>
    <p>not sure I got right what is the issue and what would be a
      solution for it, but maybe you can leverage evrexec to create a
      child process and by that keep it in kamailio children list.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div>On 13.09.22 19:15, Marat Gareev wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Hello!
        <div><br>
        </div>
        <div>I'm trying to use app_python module to perform periodic
          actions.</div>
        <div><br>
        </div>
        <div>This is a simple python code</div>
        <div>
          <div style="color:rgb(51,51,51);background-color:rgb(245,245,245);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">_update</span><span style="color:rgb(119,119,119)">():</span></div><div>    <span style="color:rgb(75,105,198)">while</span> <span style="color:rgb(156,93,39)">True</span><span style="color:rgb(119,119,119)">:</span></div><div><span style="color:rgb(119,119,119)">        </span>_action<span style="color:rgb(119,119,119)">()</span></div><div>        time<span style="color:rgb(119,119,119)">.</span>sleep<span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">60</span><span style="color:rgb(119,119,119)">)</span></div>
<div><span style="color:rgb(122,62,157)">class</span> <span style="color:rgb(122,62,157);font-weight:bold">noop_handler</span><span style="color:rgb(119,119,119)">:</span></div><div>    <span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">child_init</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">self</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(122,62,157)">rank</span><span style="color:rgb(119,119,119)">):</span></div><div>        <span style="color:rgb(75,105,198)">return</span> <span style="color:rgb(156,93,39)">0</span></div>
<div>    <span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">ksr_request_route</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">self</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(122,62,157)">msg</span><span style="color:rgb(119,119,119)">):</span></div><div>        <span style="color:rgb(75,105,198)">return</span> <span style="color:rgb(156,93,39)">1</span></div>
<div><span style="color:rgb(122,62,157)">def</span> <span style="color:rgb(170,55,49);font-weight:bold">mod_init</span><span style="color:rgb(119,119,119)">():</span></div><div>    <span style="color:rgb(170,170,170);font-style:italic"># signal.signal(signal.SIGTERM, signal.default_int_handler)</span></div><div>    <span style="color:rgb(122,62,157)">proc</span> <span style="color:rgb(119,119,119)">=</span> multiprocessing<span style="color:rgb(119,119,119)">.</span>Process<span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">target</span><span style="color:rgb(119,119,119)">=</span><span style="color:rgb(170,55,49);font-weight:bold">_update</span><span style="color:rgb(119,119,119)">)</span></div><div>    <span style="color:rgb(170,170,170);font-style:italic"># proc.daemon = True</span></div><div>    <span style="color:rgb(122,62,157)">proc</span><span style="color:rgb(119,119,119)">.</span>start<span style="color:rgb(119,119,119)">()</span></div><div>    ksr<span style="color:rgb(119,119,119)">.</span>notice<span style="color:rgb(119,119,119)">(</span><span style="color:rgb(119,119,119)">'</span><span style="color:rgb(68,140,39)">Forked process </span><span style="color:rgb(156,93,39)">{}</span><span style="color:rgb(68,140,39)"> to update</span><span style="color:rgb(119,119,119)">\n'</span><span style="color:rgb(119,119,119)">.</span><span style="color:rgb(170,55,49);font-weight:bold">format</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(122,62,157)">proc</span><span style="color:rgb(119,119,119)">.</span>pid<span style="color:rgb(119,119,119)">))</span></div><div>    <span style="color:rgb(75,105,198)">return</span> <span style="color:rgb(122,62,157);font-weight:bold">noop_handler</span><span style="color:rgb(119,119,119)">()</span></div></div>
        </div>
        <div><br>
        </div>
        <div>After killing kamailio processes with SIGTERM signal (<span style="background-color:rgb(245,245,245);color:rgb(51,51,51);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap">killall kamailio</span>)
          I see zombie process.</div>
        <div>And if I try to process the signal in daemon mode (see the
          comments in the snippet above), I get critical errors in the
          logs and still see processes:</div>
        <div>
          <div style="color:rgb(51,51,51);background-color:rgb(245,245,245);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div> <span style="color:rgb(156,93,39)">0</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37001</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">NOTICE</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>kemi<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">124</span><span style="color:rgb(119,119,119)">]:</span> sr_kemi_core_notice<span style="color:rgb(119,119,119)">():</span> Forked process <span style="color:rgb(156,93,39)">37002</span> to update</div><div> <span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37003</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ERROR</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>udp_server<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">464</span><span style="color:rgb(119,119,119)">]:</span> udp_rcv_loop<span style="color:rgb(119,119,119)">():</span> recvfrom<span style="color:rgb(119,119,119)">:[</span><span style="color:rgb(156,93,39)">4</span><span style="color:rgb(119,119,119)">]</span> Interrupted system call</div><div>Process Process<span style="color:rgb(119,119,119)">-</span><span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">:</span></div><div>Traceback <span style="color:rgb(119,119,119)">(</span>most recent call last<span style="color:rgb(119,119,119)">):</span></div><div>  File <span style="color:rgb(119,119,119)">"</span><span style="color:rgb(68,140,39)">/usr/lib64/python2.7/multiprocessing/process.py</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(119,119,119)">,</span> line <span style="color:rgb(156,93,39)">258</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">in</span> _bootstrap</div><div>    <span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>run<span style="color:rgb(119,119,119)">()</span></div><div>  File <span style="color:rgb(119,119,119)">"</span><span style="color:rgb(68,140,39)">/usr/lib64/python2.7/multiprocessing/process.py</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(119,119,119)">,</span> line <span style="color:rgb(156,93,39)">114</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">in</span> run</div><div>    <span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>_target<span style="color:rgb(119,119,119)">(*</span><span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>_args<span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">**</span><span style="color:rgb(156,93,39)">self</span><span style="color:rgb(119,119,119)">.</span>_kwargs<span style="color:rgb(119,119,119)">)</span></div><div>  File <span style="color:rgb(119,119,119)">"</span><span style="color:rgb(68,140,39)">/tmp/script.py</span><span style="color:rgb(119,119,119)">"</span><span style="color:rgb(119,119,119)">,</span> line <span style="color:rgb(156,93,39)">155</span><span style="color:rgb(119,119,119)">,</span> <span style="color:rgb(119,119,119)">in</span> _update</div><div>    time<span style="color:rgb(119,119,119)">.</span>sleep<span style="color:rgb(119,119,119)">(</span>period<span style="color:rgb(119,119,119)">)</span></div><div><span style="color:rgb(122,62,157)">KeyboardInterrupt</span></div><div> <span style="color:rgb(156,93,39)">0</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37001</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ALERT</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>main<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">774</span><span style="color:rgb(119,119,119)">]:</span> handle_sigs<span style="color:rgb(119,119,119)">():</span> child process <span style="color:rgb(156,93,39)">37002</span> exited normally<span style="color:rgb(119,119,119)">,</span> status<span style="color:rgb(119,119,119)">=</span><span style="color:rgb(156,93,39)">1</span></div><div> <span style="color:rgb(156,93,39)">0</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37001</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">INFO</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>main<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">802</span><span style="color:rgb(119,119,119)">]:</span> handle_sigs<span style="color:rgb(119,119,119)">():</span> terminating due to <span style="color:rgb(156,93,39)">SIGCHLD</span></div><div> <span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37003</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ERROR</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>udp_server<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">464</span><span style="color:rgb(119,119,119)">]:</span> udp_rcv_loop<span style="color:rgb(119,119,119)">():</span> recvfrom<span style="color:rgb(119,119,119)">:[</span><span style="color:rgb(156,93,39)">4</span><span style="color:rgb(119,119,119)">]</span> Interrupted system call</div><div> <span style="color:rgb(156,93,39)">8</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37014</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">CRITICAL</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>pass_fd<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">277</span><span style="color:rgb(119,119,119)">]:</span> receive_fd<span style="color:rgb(119,119,119)">():</span> <span style="color:rgb(156,93,39)">EOF</span> on <span style="color:rgb(156,93,39)">4</span></div><div> <span style="color:rgb(156,93,39)">1</span><span style="color:rgb(119,119,119)">(</span><span style="color:rgb(156,93,39)">37003</span><span style="color:rgb(119,119,119)">)</span> <span style="color:rgb(122,62,157)">ERROR</span><span style="color:rgb(119,119,119)">:</span> <span style="color:rgb(119,119,119)"><</span>core<span style="color:rgb(119,119,119)">></span> <span style="color:rgb(119,119,119)">[</span>core<span style="color:rgb(119,119,119)">/</span>udp_server<span style="color:rgb(119,119,119)">.</span>c<span style="color:rgb(119,119,119)">:</span><span style="color:rgb(156,93,39)">464</span><span style="color:rgb(119,119,119)">]:</span> udp_rcv_loop<span style="color:rgb(119,119,119)">():</span> recvfrom<span style="color:rgb(119,119,119)">:[</span><span style="color:rgb(156,93,39)">4</span><span style="color:rgb(119,119,119)">]</span> Interrupted system call</div></div>
        </div>
        <div><br>
        </div>
        <div>So, how I can kill child process by SIGTERM signal?</div>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
  * <a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a>
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
  * <a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <pre cols="72">-- 
Daniel-Constantin Mierla -- <a href="http://www.asipto.com" target="_blank">www.asipto.com</a>
<a href="http://www.twitter.com/miconda" target="_blank">www.twitter.com/miconda</a> -- <a href="http://www.linkedin.com/in/miconda" target="_blank">www.linkedin.com/in/miconda</a></pre>
  </div>

</blockquote></div>