pyobs-core 2.29.0.dev2__py3-none-any.whl → 2.29.0.dev3__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
 
@@ -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.dev3
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
@@ -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.dev3.dist-info/METADATA,sha256=dkzZ2eTt7yaf479R0RTbeu5xNiHE-4WcBf9tkZ0Dw2s,3928
483
+ pyobs_core-2.29.0.dev3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
484
+ pyobs_core-2.29.0.dev3.dist-info/entry_points.txt,sha256=0ceIn3dTDwWdGdJ5VdTvYim7vKkdTe6aqqpoaG065UY,109
485
+ pyobs_core-2.29.0.dev3.dist-info/licenses/LICENSE,sha256=Za86Qj8Jl9nLP446ogz9uK_nKoD5qJLcNZj6Qu2UdFQ,1101
486
+ pyobs_core-2.29.0.dev3.dist-info/RECORD,,