-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (27 loc) · 1.04 KB
/
app.py
File metadata and controls
36 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import signal, os, sys
import time
from flask import Flask
app = Flask(__name__)
# Define route "/" named "index"
@app.route('/')
def index():
return '🎉 Congratulations! Your first Python3 application is running on Stackhero!'
# You'll see this log directly on your Stackhero's console
print('🎉 The app has just start!')
# Handle termination signal
# When you will push your new code to Stackhero, we will send a termination signal (SIGTERM) to your running app.
# The goal here is to let your app closing connections properly, like connections to databases etc...
sigtermHandled = False
def sigtermHandler(signum, frame):
# Avoid to execute multiple time this function
global sigtermHandled
if sigtermHandled == True:
return
sigtermHandled = True
# You'll see this log directly on your Stackhero's console
print('😯 SIGTERM signal received')
# You can close your database connection and do other cleanup here
# dbConnection.close()
# Finally exit the process
sys.exit(0)
signal.signal(signal.SIGTERM, sigtermHandler)