-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_fernando.py
More file actions
58 lines (46 loc) · 1.36 KB
/
run_fernando.py
File metadata and controls
58 lines (46 loc) · 1.36 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from src import create_app, socketio
from src.config import config
from src.services.pty_service import pty_service
import os
import signal
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(name)s %(levelname)s %(message)s",
)
logger = logging.getLogger("fernando")
app = create_app()
# Restore any saved terminal sessions from previous run
pty_service.restore_all()
def _reap_children():
"""Reap any zombie child processes."""
while True:
try:
pid, _ = os.waitpid(-1, os.WNOHANG)
if pid == 0:
break
logger.info(f"Reaped zombie child pid={pid}")
except ChildProcessError:
break
def _shutdown(signum, frame):
logger.info(f"Received signal {signum}, shutting down...")
pty_service.cleanup_all()
_reap_children()
raise SystemExit(0)
# Install SIGCHLD handler to auto-reap children
def _sigchld_handler(signum, frame):
_reap_children()
signal.signal(signal.SIGCHLD, _sigchld_handler)
signal.signal(signal.SIGTERM, _shutdown)
signal.signal(signal.SIGINT, _shutdown)
if __name__ == "__main__":
env = os.environ.get("FLASK_ENV", "development")
cfg = config[env]
socketio.run(
app,
host=cfg.HOST,
port=cfg.PORT,
debug=cfg.DEBUG,
use_reloader=False,
allow_unsafe_werkzeug=True,
)