File tree 2 files changed +33
-2
lines changed
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1
1
run :
2
- gunicorn app:app -b 0.0.0.0:8080
2
+ gunicorn app:app \
3
+ --error-logfile - \
4
+ -b 0.0.0.0:8080
Original file line number Diff line number Diff line change
1
+ import signal , os , sys
2
+ import time
1
3
from flask import Flask
2
4
app = Flask (__name__ )
3
5
4
6
# Define route "/" named "index"
5
7
@app .route ('/' )
6
8
def index ():
7
- return '🎉 Congratulations! Your first Python3 application is running on Stackhero!'
9
+ return '🎉 Congratulations! Your first Python3 application is running on Stackhero!'
10
+
11
+
12
+ # You'll see this log directly on your Stackhero's console
13
+ print ('🎉 The app has just start!' )
14
+
15
+
16
+ # Handle termination signal
17
+ # When you will push your new code to Stackhero, we will send a termination signal (SIGTERM) to your running app.
18
+ # The goal here is to let your app closing connections properly, like connections to databases etc...
19
+ sigtermHandled = False
20
+ def sigtermHandler (signum , frame ):
21
+ # Avoid to execute multiple time this function
22
+ global sigtermHandled
23
+ if sigtermHandled == True :
24
+ return
25
+ sigtermHandled = True
26
+
27
+ # You'll see this log directly on your Stackhero's console
28
+ print ('😯 SIGTERM signal received' )
29
+
30
+ # You can close your database connection and do other cleanup here
31
+ # dbConnection.close()
32
+
33
+ # Finally exit the process
34
+ sys .exit (0 )
35
+
36
+ signal .signal (signal .SIGTERM , sigtermHandler )
You can’t perform that action at this time.
0 commit comments