Python-twisted and SIGKILL

I have a python application that uses a twisted structure.

I use the value stored in the pidfile generated by the twist. Launcher script checks for the presence and will not start the daemon process if the pidfile already exists.

However, twistd does not remove .pidfile when it receives a SIGKILL signal. This makes the script launcher assume that the daemon is already running.

I understand that the correct way to stop the daemon would be to use the SIGTERM signal, but the problem is that when the user who started the daemon logs out, the daemon never receives the SIGTERM signal, so it seems that it was killed by SIGKILL . This means that when the user logs out, he will never be able to start the daemon again, because the pidfile still exists.

Is there any way to delete this file in such situations?

+4
source share
2 answers

On the signal(2) man page:

SIGKILL and SIGSTOP signals cannot be caught or ignored.

Thus, in response to this signal, the process cannot trigger any clear code. Usually you use only SIGKILL to complete a process that does not respond to SIGTERM (which can be caught).

+4
source

You can change your launcher (or terminate it in another launcher) and delete the pid file before trying to restart twistd.

0
source

Source: https://habr.com/ru/post/1445027/


All Articles