Fix srun detection causing permission error on non-SLURM platforms (#15485)
* improve srun detection * changelog * try catch is obsolete Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
5025c3ec16
commit
9c20cad40e
|
@ -48,7 +48,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
### Fixed
|
||||
|
||||
-
|
||||
- Fix an issue with the SLURM `srun` detection causing permission errors ([#15485](https://github.com/Lightning-AI/lightning/issues/15485))
|
||||
|
||||
-
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
|
@ -160,10 +160,8 @@ class SLURMEnvironment(ClusterEnvironment):
|
|||
"""
|
||||
if _IS_WINDOWS:
|
||||
return
|
||||
try:
|
||||
srun_exists = subprocess.call(["command", "-v", "srun"]) == 0
|
||||
except FileNotFoundError:
|
||||
srun_exists = False
|
||||
|
||||
srun_exists = shutil.which("srun") is not None
|
||||
if srun_exists and not _is_srun_used():
|
||||
hint = " ".join(["srun", os.path.basename(sys.executable), *sys.argv])[:64]
|
||||
rank_zero_warn(
|
||||
|
|
|
@ -126,7 +126,7 @@ def test_srun_available_and_not_used(monkeypatch):
|
|||
expected = "`srun` .* available .* but is not used. HINT: .* srun python train.py --lr 0.01"
|
||||
|
||||
# pretend `srun` is available
|
||||
with mock.patch("lightning_lite.plugins.environments.slurm.subprocess.call", return_value=0):
|
||||
with mock.patch("lightning_lite.plugins.environments.slurm.shutil.which", return_value="/usr/bin/srun"):
|
||||
with pytest.warns(PossibleUserWarning, match=expected):
|
||||
SLURMEnvironment()
|
||||
|
||||
|
|
Loading…
Reference in New Issue