|
18 | 18 | import signal |
19 | 19 | import subprocess |
20 | 20 | import sys |
| 21 | +import time |
21 | 22 |
|
22 | 23 |
|
23 | 24 | def _signal_supervisord() -> None: |
@@ -83,22 +84,32 @@ def _mark_external_shutdown(signum, frame): |
83 | 84 |
|
84 | 85 |
|
85 | 86 | def _run_shell_recorder(): |
| 87 | + record_video = os.environ.get("SE_RECORD_VIDEO", "true").lower() == "true" |
| 88 | + per_session_mode = os.environ.get("SE_VIDEO_FILE_NAME", "") == "auto" |
| 89 | + |
| 90 | + if not record_video and not per_session_mode: |
| 91 | + print("[video.recorder] - SE_RECORD_VIDEO is disabled and SE_VIDEO_FILE_NAME is not 'auto', idling.") |
| 92 | + try: |
| 93 | + while True: |
| 94 | + time.sleep(60) |
| 95 | + except KeyboardInterrupt: |
| 96 | + pass |
| 97 | + return |
| 98 | + |
86 | 99 | proc = subprocess.Popen(["/opt/bin/video.sh"]) |
87 | 100 | _external_shutdown = False # True when supervisord (or user) told us to stop |
88 | 101 |
|
89 | 102 | def forward_signal(signum, frame): |
90 | 103 | nonlocal _external_shutdown |
91 | | - # Forward the signal to video.sh at most once. supervisord uses |
92 | | - # killasgroup=true so video.sh already received the signal directly; |
93 | | - # re-forwarding on every re-entrant call amplifies the SIGTERM |
94 | | - # ping-pong and can keep the process alive for 60 s. |
95 | 104 | if not _external_shutdown: |
96 | 105 | _external_shutdown = True |
97 | 106 | try: |
98 | 107 | proc.send_signal(signum) |
99 | 108 | except ProcessLookupError: |
100 | | - pass # Process already exited before signal was forwarded |
101 | | - proc.wait() |
| 109 | + pass |
| 110 | + # Do NOT call proc.wait() here — blocking inside a signal handler |
| 111 | + # interferes with bash's deferred-signal queue. The main-flow |
| 112 | + # proc.wait() below resumes automatically after this returns (PEP 475). |
102 | 113 |
|
103 | 114 | signal.signal(signal.SIGTERM, forward_signal) |
104 | 115 | signal.signal(signal.SIGINT, forward_signal) |
|
0 commit comments