Hello,

 

not a KEMI python expert, but what you are trying to do (adding a process to Kamailio and then also maintaining it during run-time) could be probably better done from the C module level.

You can look to the several modules that starts their own children worker processes to get an idea how to do it.

 

Cheers,

 

Henning

 

--

Henning Westerholt – https://skalatan.de/blog/

Kamailio services – https://gilawa.com

 

From: sr-users <sr-users-bounces@lists.kamailio.org> On Behalf Of Marat Gareev
Sent: Wednesday, October 26, 2022 12:19 PM
To: miconda@gmail.com
Cc: Kamailio (SER) - Users Mailing List <sr-users@lists.kamailio.org>
Subject: Re: [SR-Users] Kill child process created by app_python module

 

Hello again,

 

Any advice will be appreciated.

 

Thanks

 

чт, 15 сент. 2022 г. в 18:10, Marat Gareev <maratkin94@gmail.com>:

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 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 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@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@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.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda