Commit fde7321
fix(standalone): graceful shutdown of embedded postgres on signal
`testgen run-app` was leaving orphan postgres processes after Ctrl+C in
standalone (pip) mode, breaking `tg delete` (data dir locked).
pixeltable-pgserver tracks handles via a disk-backed PID registry at
`<pgdata>/.handle_pids.json` and only stops postgres when the calling PID
is the last one registered. Two paths were leaking PIDs into the registry:
1. Each `run-app all` child re-entered `cli()` and called `start_server()`
itself, registering its own PID alongside the parent's.
2. On Windows, `_forward_signal_to_child` used `terminate()`
(TerminateProcess), so children's atexit never ran — their PIDs
stayed in the registry forever, and the parent's cleanup silently
no-op'd.
Fix:
- `cli()` now calls `ensure_standalone_setup(uri)` instead of
`start_server()` when `_TG_STANDALONE_URI` is inherited, so children
attach to the parent's pgserver without registering a PID.
- `run_app("all")` injects the parent's pgserver URI into `child_env`.
- `run_ui()` Streamlit env-var assembly falls back to the inherited env
var when this process doesn't own pgserver.
- New `_subprocess_spawn_kwargs()` helper: POSIX `start_new_session`,
Windows `CREATE_NEW_PROCESS_GROUP`. Applied at both `Popen` sites.
- Windows branch of `_forward_signal_to_child` now sends
`CTRL_BREAK_EVENT` instead of `terminate()`, so children's atexit and
SIGBREAK handlers run.
- New `_install_shutdown_handler()` registers SIGINT/SIGTERM/(SIGBREAK)
in one call. Used in `run_ui`, `run_app("all")`, and `Scheduler.run`.
- `run_app("all")` children-watcher loop now iterates a snapshot of
`children` so simultaneous child exits don't leave a sibling un-reaped.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 01ad413 commit fde7321
2 files changed
Lines changed: 67 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
119 | 148 | | |
120 | | - | |
121 | | - | |
122 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
123 | 153 | | |
124 | | - | |
| 154 | + | |
125 | 155 | | |
126 | 156 | | |
127 | 157 | | |
| |||
169 | 199 | | |
170 | 200 | | |
171 | 201 | | |
172 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
173 | 210 | | |
174 | 211 | | |
175 | 212 | | |
| |||
924 | 961 | | |
925 | 962 | | |
926 | 963 | | |
927 | | - | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
928 | 967 | | |
929 | 968 | | |
930 | | - | |
| 969 | + | |
931 | 970 | | |
932 | | - | |
| 971 | + | |
933 | 972 | | |
934 | | - | |
| 973 | + | |
935 | 974 | | |
936 | 975 | | |
937 | 976 | | |
| |||
950 | 989 | | |
951 | 990 | | |
952 | 991 | | |
| 992 | + | |
953 | 993 | | |
954 | 994 | | |
955 | 995 | | |
956 | 996 | | |
957 | | - | |
958 | | - | |
| 997 | + | |
959 | 998 | | |
960 | 999 | | |
961 | 1000 | | |
| |||
980 | 1019 | | |
981 | 1020 | | |
982 | 1021 | | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
983 | 1025 | | |
984 | | - | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
985 | 1031 | | |
986 | 1032 | | |
987 | 1033 | | |
988 | 1034 | | |
989 | 1035 | | |
990 | 1036 | | |
991 | 1037 | | |
992 | | - | |
993 | | - | |
| 1038 | + | |
994 | 1039 | | |
995 | 1040 | | |
996 | 1041 | | |
| |||
999 | 1044 | | |
1000 | 1045 | | |
1001 | 1046 | | |
1002 | | - | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
1003 | 1051 | | |
1004 | 1052 | | |
1005 | 1053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
198 | 202 | | |
199 | 203 | | |
200 | 204 | | |
| |||
0 commit comments