简体   繁体   中英

python-twisted and SIGKILL

I have a python application that uses twisted framework.

I make use of value stored in the pidfile generated by twistd. A launcher script checks for it's presence and will not spawn a daemon process if the pidfile already exists.

However, twistd does not remove the .pidfile when it gets SIGKILL signal. That makes the launcher script think that the daemon is already running.

I realize the proper way to stop the daemon would be to use SIGTERM signal, but the problem is that when user who started the daemon logs out, the daemon never gets a SIGTERM signal, so apparently it's killed with SIGKILL . That means once a user logs out, he will never be able to start the daemon again, because the pidfile still exists.

Is there any way I could make that file disappear in such situations?

From the signal(2) man page:

The signals SIGKILL and SIGSTOP cannot be caught or ignored.

So there is no way the process can run any cleanup code in response to that signal. Usually you only use SIGKILL to terminate a process that doesn't exit in response to SIGTERM (which can be caught).

您可以更改启动器(或将其包装在另一个启动器中)并在尝试重新启动twistd之前删除pid文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM