pyobs-core 2.29.0.dev2__py3-none-any.whl → 2.29.0.dev4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyobs/cli/pyobsd.py CHANGED
@@ -20,6 +20,9 @@ from ._cli import CLI
20
20
 
21
21
  log = logging.getLogger("pyobs")
22
22
 
23
+ # how long "stop --kill" waits for a killed module to be gone
24
+ _KILL_WAIT_SECONDS = 5.0
25
+
23
26
 
24
27
  class PyobsDaemonCLI(CLI):
25
28
  """Class for initializing and running pyobsd CLI."""
@@ -82,7 +85,16 @@ class PyobsDaemonCLI(CLI):
82
85
  stop_parser.add_argument(
83
86
  "--no-wait", action="store_true", help="only send SIGTERM, do not wait for the modules to exit"
84
87
  )
85
- sp.add_parser("restart", help="restart modules").add_argument("modules", type=str, nargs="*")
88
+ stop_parser.add_argument(
89
+ "--kill",
90
+ action="store_true",
91
+ help="send SIGKILL right away, e.g. for a module whose shutdown hangs (cuts a camera's warm-up)",
92
+ )
93
+ restart_parser = sp.add_parser("restart", help="restart modules")
94
+ restart_parser.add_argument("modules", type=str, nargs="*")
95
+ restart_parser.add_argument(
96
+ "--kill", action="store_true", help="send SIGKILL right away instead of a normal stop, then start"
97
+ )
86
98
  status_parser = sp.add_parser("status", help="status of modules")
87
99
  status_parser.add_argument("--json", action="store_true")
88
100
  status_parser.add_argument(
@@ -117,9 +129,12 @@ class PyobsDaemonCLI(CLI):
117
129
  case "start":
118
130
  daemon.start(modules=self._config["modules"])
119
131
  case "stop":
120
- daemon.stop(modules=self._config["modules"], wait=not self._config["no_wait"])
132
+ if self._config["kill"]:
133
+ daemon.kill(modules=self._config["modules"])
134
+ else:
135
+ daemon.stop(modules=self._config["modules"], wait=not self._config["no_wait"])
121
136
  case "restart":
122
- daemon.restart(modules=self._config["modules"])
137
+ daemon.restart(modules=self._config["modules"], kill=self._config["kill"])
123
138
  case "status":
124
139
  daemon.status(print_json=self._config["json"], cpu_interval=self._config["cpu_interval"])
125
140
  case "list":
@@ -341,8 +356,46 @@ class PyobsDaemon:
341
356
  print(f'{module} keeps shutting down in the background{until}, see "pyobsd status".')
342
357
  sys.exit(130)
343
358
 
344
- def restart(self, modules: list[str] | None = None) -> None:
345
- self.stop(modules=modules)
359
+ def kill(self, modules: list[str] | None = None) -> None:
360
+ """Sends SIGKILL right away, without a shutdown, e.g. to a module whose shutdown hangs, and removes its run
361
+ files. Without modules, kills all that have a live PID."""
362
+ if not modules:
363
+ modules = [m for m in self._list_configs() if self._running_pid(m) is not None]
364
+
365
+ killed: dict[str, int] = {}
366
+ for module in modules:
367
+ pid = self._running_pid(module)
368
+ if pid is None:
369
+ print(f"{module} is not running.")
370
+ continue
371
+ print(f"Killing {module}...")
372
+ try:
373
+ os.kill(pid, signal.SIGKILL)
374
+ except OSError:
375
+ pass
376
+ killed[module] = pid
377
+
378
+ # SIGKILL can't end a process stuck in the kernel (e.g. in a USB driver call) until that call returns. Keep
379
+ # the PID file of such a process, so that it doesn't show as stopped and can't be started a second time
380
+ deadline = time.time() + _KILL_WAIT_SECONDS
381
+ while killed:
382
+ for module, pid in list(killed.items()):
383
+ if not self._is_alive(pid):
384
+ self._remove_run_files(module)
385
+ del killed[module]
386
+ if not killed or time.time() >= deadline:
387
+ break
388
+ time.sleep(0.1)
389
+ for module, pid in killed.items():
390
+ print(f"{module} (PID {pid}) is still alive after SIGKILL, probably stuck in a driver call.")
391
+ if killed:
392
+ sys.exit(1)
393
+
394
+ def restart(self, modules: list[str] | None = None, kill: bool = False) -> None:
395
+ if kill:
396
+ self.kill(modules=modules)
397
+ else:
398
+ self.stop(modules=modules)
346
399
  time.sleep(1)
347
400
  self.start(modules=modules)
348
401
 
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import asyncio
4
4
  import logging
5
+ import time
5
6
  from typing import Any
6
7
 
7
8
  from pyobs.interfaces import CoolingState
@@ -19,6 +20,8 @@ _CLOSE_MARGIN_SECONDS = 60.0
19
20
  _CLOSE_FALLBACK_TIMEOUT = 300.0
20
21
  # extra time asked from pyobsd/systemd on top of the warm-up, for the rest of close()
21
22
  _STOP_TIMEOUT_EXTRA_SECONDS = 30.0
23
+ # how often the warm-up on close logs its progress, in seconds
24
+ _WARMUP_LOG_INTERVAL = 60.0
22
25
 
23
26
 
24
27
  class CoolingRampMixin:
@@ -150,7 +153,7 @@ class CoolingRampMixin:
150
153
  extend_stop_timeout(timeout + _STOP_TIMEOUT_EXTRA_SECONDS)
151
154
  self._cooling_target = (False, None)
152
155
  try:
153
- await asyncio.wait_for(self._cooling_run_to_end(), timeout)
156
+ await asyncio.wait_for(self._cooling_warm_up(timeout), timeout)
154
157
  except TimeoutError:
155
158
  log.warning(
156
159
  "Warm-up on close did not finish within %.0fs (setpoint at %s). "
@@ -190,11 +193,41 @@ class CoolingRampMixin:
190
193
 
191
194
  # ramp -------------------------------------------------------------------------------------------------------
192
195
 
193
- async def _cooling_run_to_end(self) -> None:
196
+ async def _cooling_warm_up(self, timeout: float) -> None:
197
+ """Runs the warm-up ramp to its end. Logs when it starts, about every _WARMUP_LOG_INTERVAL seconds while it
198
+ runs, and when it is done, so the log shows why the module takes long to stop."""
199
+ start = time.monotonic()
200
+ delay = await self._cooling_tick()
201
+ if self._cooling_target is None:
202
+ return # cooler was off already, or switched off in the first step
203
+ log.info(
204
+ "Warming up from %s towards %.1f °C before closing, may take up to %s.",
205
+ _temperature(self._cooling_commanded),
206
+ self._cooling_ramp.off_temperature,
207
+ _duration(timeout),
208
+ )
209
+ next_log = start + _WARMUP_LOG_INTERVAL
194
210
  while self._cooling_target is not None:
195
- delay = await self._cooling_tick()
196
211
  if delay:
197
212
  await asyncio.sleep(delay)
213
+ delay = await self._cooling_tick()
214
+ now = time.monotonic()
215
+ if self._cooling_target is not None and now >= next_log:
216
+ await self._cooling_log_warm_up(start + timeout - now)
217
+ next_log = now + _WARMUP_LOG_INTERVAL
218
+ log.info("Warm-up done after %s, cooling is off.", _duration(time.monotonic() - start))
219
+
220
+ async def _cooling_log_warm_up(self, left: float) -> None:
221
+ try:
222
+ sensor = await self._get_sensor_temperature()
223
+ except Exception:
224
+ sensor = None # only for the log, the next tick reports a real problem
225
+ log.info(
226
+ "Warming up: setpoint %s, sensor %s, up to %s left.",
227
+ _temperature(self._cooling_commanded),
228
+ _temperature(sensor),
229
+ _duration(max(0.0, left)),
230
+ )
198
231
 
199
232
  async def _cooling_ramp_loop(self) -> None:
200
233
  while True:
@@ -278,4 +311,12 @@ class CoolingRampMixin:
278
311
  self._cooling_target = None
279
312
 
280
313
 
314
+ def _temperature(value: float | None) -> str:
315
+ return "unknown" if value is None else f"{value:.1f} °C"
316
+
317
+
318
+ def _duration(seconds: float) -> str:
319
+ return f"{seconds:.0f} s" if seconds < 90 else f"{seconds / 60:.0f} min"
320
+
321
+
281
322
  __all__ = ["CoolingRampMixin"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyobs-core
3
- Version: 2.29.0.dev2
3
+ Version: 2.29.0.dev4
4
4
  Summary: robotic telescope software
5
5
  Project-URL: Homepage, https://www.pyobs.org
6
6
  Project-URL: Documentation, https://docs.pyobs.org
@@ -7,7 +7,7 @@ pyobs/version.py,sha256=y7kcc_eQKcC7SFFUYIr8dhkhDYXwshVu7imSEbC9VW0,257
7
7
  pyobs/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  pyobs/cli/_cli.py,sha256=NTPVrUNE-b2MspccFEgfeDsnmtFqYTGkMpL9_tixiEc,2050
9
9
  pyobs/cli/pyobs.py,sha256=uFcIpK1prJPTom5LoC2coL0E57QqxDVHd6mjIswM-X8,4472
10
- pyobs/cli/pyobsd.py,sha256=Cq6B6lHsSzTzoPPTGBg9HJCxPeO00Qx2Oij6HwoSH8c,25352
10
+ pyobs/cli/pyobsd.py,sha256=_l1C-GI0FYsqlKu16wuU-uAd_v2wSyXzzXpEZ64oLEY,27650
11
11
  pyobs/cli/pyobsw.py,sha256=uXrJoz8fpGjADPUyf0-MxNcCKqVK2PkI8i9TWS-VS7w,740
12
12
  pyobs/comm/__init__.py,sha256=Pc_hlxXLcVf5sWtf_wCJ9PbC1_sGJHaNsF6qWBEQJzU,1567
13
13
  pyobs/comm/comm.py,sha256=-HEM8fkK62bWvg9gFRdcaKdsNAlNYnAXwU8kkfoXs64,29202
@@ -206,7 +206,7 @@ pyobs/interfaces/__init__.py,sha256=b2kRbTTOYy5EaIkpYxTk3xKDP8QK7ZyeDnD8iuUnyXk,
206
206
  pyobs/interfaces/interface.py,sha256=Qhdar9Dz4_Tb5rsflc07rjOBgp5vqxBzxdCWm--rDCc,3369
207
207
  pyobs/mixins/__init__.py,sha256=ub1Enr-jIpL9rplP9G2o-gEwm83QtHb_ATdsqSl9p8I,1041
208
208
  pyobs/mixins/camerasettings.py,sha256=r-DeJEdRIMqaa0uL0dUsrMpbHLJQL4WL9n6EkudTgI8,2541
209
- pyobs/mixins/coolingramp.py,sha256=xl0BAlhEiOosEhoNNsYtgPtcyBIU4WoBWVkcTjkEs-0,12633
209
+ pyobs/mixins/coolingramp.py,sha256=zLrBocczzhCWi6RJXjBUk2QhL13iEr4DtE99mEzNuEU,14464
210
210
  pyobs/mixins/datapipeline.py,sha256=oLVe91NozxShdU1zl9zDHfByAFhqhc_kHc84doP8rjo,5196
211
211
  pyobs/mixins/datasequence.py,sha256=sEB3i9kInxCdD22tqzP83UWtJMFcx1eOuhbfurNxsjk,5874
212
212
  pyobs/mixins/fitsheader.py,sha256=hpSoPcU8omgPgR44INMz1-eqxa3uVNmxC7e21U1cR70,23587
@@ -479,8 +479,8 @@ pyobs/vfs/vfs.py,sha256=PTZcapn4U3yr2Ksa0xfbP0ssSiJhA6_XzgmNMdNav3U,14077
479
479
  pyobs/vfs/filelists/__init__.py,sha256=NaTGFjLGh043j_F7kWEx_cXaII7t3CbYguRk2g5hEqw,111
480
480
  pyobs/vfs/filelists/filelist.py,sha256=kCco_5G2gLH-nxWik-wcs6lGuc_-3LeeyR9L4_srf30,201
481
481
  pyobs/vfs/filelists/testing.py,sha256=M8f2BULdjRCc7JFOKhAH7Kwre_uVQC0xLcv9xGTfNFw,425
482
- pyobs_core-2.29.0.dev2.dist-info/METADATA,sha256=8iXmY86MTsIsqdt614xLBddg5t3nz0C-2m4_z2iKxyo,3928
483
- pyobs_core-2.29.0.dev2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
484
- pyobs_core-2.29.0.dev2.dist-info/entry_points.txt,sha256=0ceIn3dTDwWdGdJ5VdTvYim7vKkdTe6aqqpoaG065UY,109
485
- pyobs_core-2.29.0.dev2.dist-info/licenses/LICENSE,sha256=Za86Qj8Jl9nLP446ogz9uK_nKoD5qJLcNZj6Qu2UdFQ,1101
486
- pyobs_core-2.29.0.dev2.dist-info/RECORD,,
482
+ pyobs_core-2.29.0.dev4.dist-info/METADATA,sha256=97x4anZ5Ox4pKH1qlawkWKLbSBWmlSHcau5BUo8t3Cg,3928
483
+ pyobs_core-2.29.0.dev4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
484
+ pyobs_core-2.29.0.dev4.dist-info/entry_points.txt,sha256=0ceIn3dTDwWdGdJ5VdTvYim7vKkdTe6aqqpoaG065UY,109
485
+ pyobs_core-2.29.0.dev4.dist-info/licenses/LICENSE,sha256=Za86Qj8Jl9nLP446ogz9uK_nKoD5qJLcNZj6Qu2UdFQ,1101
486
+ pyobs_core-2.29.0.dev4.dist-info/RECORD,,