[SR-Users] Kill child process created by app_python module

Marat Gareev maratkin94 at gmail.com
Thu Sep 15 16:10:43 CEST 2022


Hello Daniel,

Probably, the process is not killed, because the child processes of the
python module are not included in the kamailio children list.

How can I register an event route in KEMI script?
Doc
<https://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/kemi/#python-kemi-interpreter>
says:

> 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

but evrexec
<https://www.kamailio.org/docs/modules/devel/modules/evrexec.html> doesn't
have an event_callback parameter.

I tried to set up exec parameter (_update is Python function)
modparam("evrexec", "exec", "name=_update;workers=1;")
and got warning
WARNING: evrexec [evrexec_mod.c:180]: evrexec_process(): empty event route
block [_update]


ср, 14 сент. 2022 г. в 16:21, Daniel-Constantin Mierla <miconda at gmail.com>:

> Hello,
>
> 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.
>
> Cheers,
> Daniel
> On 13.09.22 19:15, Marat Gareev wrote:
>
> Hello!
>
> I'm trying to use app_python module to perform periodic actions.
>
> This is a simple python code
> def _update():
> while True:
> _action()
> time.sleep(60)
> class noop_handler:
> def child_init(self, rank):
> return 0
> def ksr_request_route(self, msg):
> return 1
> def mod_init():
> # signal.signal(signal.SIGTERM, signal.default_int_handler)
> proc = multiprocessing.Process(target=_update)
> # proc.daemon = True
> proc.start()
> ksr.notice('Forked process {} to update\n'.format(proc.pid))
> return noop_handler()
>
> After killing kamailio processes with SIGTERM signal (killall kamailio) I
> see zombie process.
> 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:
> 0(37001) NOTICE: <core> [core/kemi.c:124]: sr_kemi_core_notice(): Forked
> process 37002 to update
> 1(37003) ERROR: <core> [core/udp_server.c:464]: udp_rcv_loop(): recvfrom:[
> 4] Interrupted system call
> Process Process-1:
> Traceback (most recent call last):
> File "/usr/lib64/python2.7/multiprocessing/process.py", line 258, in
> _bootstrap
> self.run()
> File "/usr/lib64/python2.7/multiprocessing/process.py", line 114, in run
> self._target(*self._args, **self._kwargs)
> File "/tmp/script.py", line 155, in _update
> time.sleep(period)
> KeyboardInterrupt
> 0(37001) ALERT: <core> [main.c:774]: handle_sigs(): child process 37002
> exited normally, status=1
> 0(37001) INFO: <core> [main.c:802]: handle_sigs(): terminating due to
> SIGCHLD
> 1(37003) ERROR: <core> [core/udp_server.c:464]: udp_rcv_loop(): recvfrom:[
> 4] Interrupted system call
> 8(37014) CRITICAL: <core> [core/pass_fd.c:277]: receive_fd(): EOF on 4
> 1(37003) ERROR: <core> [core/udp_server.c:464]: udp_rcv_loop(): recvfrom:[
> 4] Interrupted system call
>
> So, how I can kill child process by SIGTERM signal?
>
> __________________________________________________________
> Kamailio - Users Mailing List - Non Commercial Discussions
>   * sr-users at lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to the sender!
> Edit mailing list options or unsubscribe:
>   * https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
> --
> Daniel-Constantin Mierla -- www.asipto.comwww.twitter.com/miconda -- www.linkedin.com/in/miconda
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20220915/3830abc6/attachment.htm>


More information about the sr-users mailing list