Skip to content
Ken Hibino edited this page Jan 20, 2020 · 5 revisions

This page explains how to use signals to gracefully shut down background process.

When you start the background processing with Background.Run(Handler), it will block and wait for incoming signals.

There are two types of signals you can send to the running program to gracefully shutdown the background processing.

  • TSTP : This signal tells Background to stop processing new tasks.
  • TERM or INT : This signal tells Background to terminate.

It's recommended that you first send TSTP signal to stop processing new tasks and wait for all in-progress tasks to finish before sending TERM signal to terminate the program.

Use kill command to send signals.

kill -TSTP <pid> # stop processing new tasks

kill -TERM <pid> # terminate the program

Note: If you send TERM or INT signal without sending TSTP signal, the Background will start a timer for 8 seconds to allow for all workers to finish. If there are workers that didn't finish within that time frame, the task will be transitioned back to enqueued state and will be processed once the program restarts.

Clone this wiki locally