Forums

Proper cleanup for connections in long-running (6 hr) processes given a SIGKILL signal

As an uncatchable SIGKILL signal will be sent to long-running processes [1] past a 6-hour limit, are there any recommendations on how to ensure database connections are closed in these cases? Should a manual timer be set in the long-running process to indicate to manually end processes just before this limit?

...or perhaps they should be expected to be disconnected automatically (if that's possible)

Edit: Side note (if useful): The long running processes are actually threads launched from within a function started from the scheduler, if the lock is acquired, and the function is kept running in a loop to prevent its exit (and the threads' exit).

[1] -- https://www.pythonanywhere.com/forums/topic/11382/

I can't think of any easy way apart from the timer solution that you suggested. But one thing that's worth noting is that database connections are automatically closed by the server if they are inactive for five minutes -- this means that when your long-running process is shut down, the connections will time out shortly thereafter.