Set a signal handler to gracefully exit on the given signal. When this process receives the given signal, it will run `atexit` handlers and then exit with `0`. Args: signal_number: The numeric code for the signal to handle, like `signal.SIGTERM`.
(self, signal_number, signal_name)
| 344 | manager.write_info_file(info) |
| 345 | |
| 346 | def _install_signal_handler(self, signal_number, signal_name): |
| 347 | """Set a signal handler to gracefully exit on the given signal. |
| 348 | |
| 349 | When this process receives the given signal, it will run `atexit` |
| 350 | handlers and then exit with `0`. |
| 351 | |
| 352 | Args: |
| 353 | signal_number: The numeric code for the signal to handle, like |
| 354 | `signal.SIGTERM`. |
| 355 | signal_name: The human-readable signal name. |
| 356 | """ |
| 357 | # Note to maintainers: Google-internal code overrides this |
| 358 | # method (cf. cl/334534610). Double-check changes before |
| 359 | # modifying API. |
| 360 | |
| 361 | old_signal_handler = None # set below |
| 362 | |
| 363 | def handler(handled_signal_number, frame): |
| 364 | # In case we catch this signal again while running atexit |
| 365 | # handlers, take the hint and actually die. |
| 366 | signal.signal(signal_number, signal.SIG_DFL) |
| 367 | sys.stderr.write( |
| 368 | "TensorBoard caught %s; exiting...\n" % signal_name |
| 369 | ) |
| 370 | # The main thread is the only non-daemon thread, so it suffices to |
| 371 | # exit hence. |
| 372 | if old_signal_handler not in (signal.SIG_IGN, signal.SIG_DFL): |
| 373 | old_signal_handler(handled_signal_number, frame) |
| 374 | sys.exit(0) |
| 375 | |
| 376 | old_signal_handler = signal.signal(signal_number, handler) |
| 377 | |
| 378 | def _fix_mime_types(self): |
| 379 | """Fix incorrect entries in the `mimetypes` registry. |