File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ def save_vote() -> Response:
89
89
90
90
91
91
# https://cloud.google.com/blog/topics/developers-practitioners/graceful-shutdowns-cloud-run-deep-dive
92
+ # [START cloudrun_sigterm_handler]
92
93
def shutdown_handler (signal : int , frame : FrameType ) -> None :
93
94
logger .info ("Signal received, safely shutting down." )
94
95
database .shutdown ()
@@ -97,11 +98,15 @@ def shutdown_handler(signal: int, frame: FrameType) -> None:
97
98
sys .exit (0 )
98
99
99
100
101
+ # [END cloudrun_sigterm_handler]
102
+
100
103
if __name__ == "__main__" :
101
104
# handles Ctrl-C locally
102
105
signal .signal (signal .SIGINT , shutdown_handler )
103
106
104
107
app .run (host = "127.0.0.1" , port = 8080 , debug = True )
105
108
else :
106
109
# handles Cloud Run container termination
110
+ # [START cloudrun_sigterm_handler]
107
111
signal .signal (signal .SIGTERM , shutdown_handler )
112
+ # [END cloudrun_sigterm_handler]
You can’t perform that action at this time.
0 commit comments