code: def safe_kill(pid, signum):
    
    assert(isinstance(pid, IntegerForPid))
    assert(isinstance(signum, int))
    try:
      os.kill(pid, signum)
    except (IOError, OSError) as e:
      if e.errno in [errno.ESRCH, errno.EPERM]:
        pass
      elif e.errno == errno.EINVAL:
        raise ValueError("Invalid signal number {}: {}"
                         .format(signum, e),
                         e)
      else:
        raise
docs: Kill a process with the specified signal, catching nonfatal errors.