classification
Title: FileNotFoundException raised by subprocess.call
Type: behavior Stage:
Components: Documentation Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Geoffrey Royer, docs@python, iritkatriel, r.david.murray
Priority: normal Keywords: easy

Created on 2015-08-18 14:36 by Geoffrey Royer, last changed 2021-06-19 17:06 by iritkatriel.

Messages (5)
msg248773 - (view) Author: Geoffrey Royer (Geoffrey Royer) Date: 2015-08-18 14:36
According to the documentation of the subprocess.check_call function: https://docs.python.org/3/library/subprocess.html#subprocess.check_call

It would be nice to notify the reader that this function can raise FileNotFoundException. It is raised in case when the binary one wants to call does not exist.

Example:

Python 3.4.0 (default, Jun 19 2015, 14:20:21) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_call(["foo", "bar"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/subprocess.py", line 552, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.4/subprocess.py", line 533, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.4/subprocess.py", line 848, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1446, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'foo'
msg248774 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-08-18 14:43
We don't in general document all the exceptions that can be raised by a piece of code.  This could be an edge case, though.  Let's see what others thing.
msg248775 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-08-18 14:44
think.
msg396107 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-18 23:07
The FileNotFoundException exception is coming from the Popen call, and the docs for subprocess.check_call already mention that it delegates to Popen.

There are quite a few different exceptions that Popen could raise, so I think David's general comment is valid, it would not make sense to mention just this one, or to try and list all of them.
msg396142 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-19 17:06
That said, the current wording does seem to imply that only CalledProcessErrors can be raised by this function so it might be worth clarifying that other exceptions can occur if the command could not run at all (without enumerating the precise exceptions).
History
Date User Action Args
2021-06-19 17:06:37iritkatrielsetkeywords: + easy

messages: + msg396142
2021-06-18 23:07:52iritkatrielsetnosy: + iritkatriel
messages: + msg396107
2015-08-18 14:53:32Geoffrey Royersettype: behavior
2015-08-18 14:47:06Geoffrey Royersetversions: + Python 3.4
2015-08-18 14:44:02r.david.murraysetmessages: + msg248775
2015-08-18 14:43:45r.david.murraysetnosy: + r.david.murray
messages: + msg248774
2015-08-18 14:36:31Geoffrey Royercreate