[sr-dev] [kamailio/kamailio] core: add a module hook for post-fork cleanup (PR #2919)

aalba6675 notifications at github.com
Fri Nov 5 15:20:59 CET 2021


How this feature will be used in app_python3 - this gives a hook to call `PyOS_AfterFork_Parent`:
```
/**
 *
 */
static pid_t main_pid = 0; /* record pid_t of main process */

static int child_init(int rank)
{
	if(rank==PROC_INIT) {
		/*
		 * this is called before any process is forked
		 * so the Python internal state handler
		 * should be called now.
		 */
#if PY_VERSION_HEX >= 0x03070000
		PyOS_BeforeFork() ;
#endif
		main_pid = getpid();
		return 0;
	}
	if(rank==PROC_POST_FORK) {
		/*
		 * this is called after all processes are forked
		 * so the Python internal state handler
		 * should be called.
		 */
#if PY_VERSION_HEX >= 0x03070000
		PyOS_AfterFork_Parent() ;
#endif
		return 0;
	}
	_apy_process_rank = rank;

	/*
	 * If non-daemonize we are called in the main context
	 * with rank = PROC_SIPINIT
	 */
	if (main_pid != getpid()) {
		/* we really are a child process */
#if PY_VERSION_HEX >= 0x03070000
		PyOS_AfterFork_Child();
#else
		PyOS_AfterFork();
#endif
	}
	if (cfg_child_init()) {
		return -1;
	}
	return apy_init_script(rank);
}
```




-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2919#issuecomment-961934666
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20211105/e38f4365/attachment.htm>


More information about the sr-dev mailing list