Ejemplo n.º 1
0
def _pr_set_pdeathsig() -> None:
    """
    Sets PR_SET_PDEATHSIG to ensure a child process is
    terminated appropriately.

    See http://stackoverflow.com/questions/1884941/ for more information.
    For libc.so.6 read http://www.linux-m68k.org/faq/glibcinfo.html
    """
    mp._prctl_pr_set_pdeathsig(signal.SIGTERM)  # type: ignore[attr-defined]
Ejemplo n.º 2
0
def _wrap(fn, kwargs, error_queue):
    # prctl(2) is a Linux specific system call.
    # On other systems the following function call has no effect.
    # This is set to ensure that non-daemonic child processes can
    # terminate if their parent terminates before they do.
    torchmp._prctl_pr_set_pdeathsig(signal.SIGINT)

    try:
        fn(**kwargs)
    except KeyboardInterrupt:
        pass  # SIGINT; Killed by parent, do nothing
    except Exception:
        # Propagate exception to parent process, keeping original traceback
        import traceback
        error_queue.put(traceback.format_exc())
        sys.exit(1)
Ejemplo n.º 3
0
 def _start(self):
     if self.subprocess_handlers:
         raise ValueError(
             "The subprocess handlers already initialized. Most likely the start method got called twice."
         )
     self.subprocess_handlers = {
         local_rank: SubprocessHandler(
             entrypoint=self.entrypoint,  # type: ignore[arg-type] # entrypoint is always a str
             args=self.args[local_rank],
             env=self.envs[local_rank],
             preexec_fn=mp._prctl_pr_set_pdeathsig(signal.SIGTERM),  # type: ignore[attr-defined]
             stdout=self.stdouts[local_rank],
             stderr=self.stderrs[local_rank],
         )
         for local_rank in range(self.nprocs)
     }