Skip to content

Commit

Permalink
Replace malformed nvidia-smi XML
Browse files Browse the repository at this point in the history
  • Loading branch information
jfennick committed Sep 19, 2023
1 parent 20f01e0 commit 67683da
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cwltool/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ def cuda_version_and_device_count() -> Tuple[str, int]:
except Exception as e:
_logger.warning("Error checking CUDA version with nvidia-smi: %s", e)
return ("", 0)
dm = xml.dom.minidom.parseString(out) # nosec

# Apparently nvidia-smi is not safe to call concurrently.
# With --parallel, sometimes the returned XML will contain
# <process_name>\xff...\xff</process_name>
# and xml.dom.minidom.parseString will raise
# "xml.parsers.expat.ExpatError: not well-formed (invalid token)"
out_no_xff = out.replace(b'\xff', b'')
dm = xml.dom.minidom.parseString(out_no_xff) # nosec

ag = dm.getElementsByTagName("attached_gpus")
if len(ag) < 1 or ag[0].firstChild is None:
Expand Down

0 comments on commit 67683da

Please sign in to comment.