New submission from Nils Kattenbeck <>:

When a FileNotFoundError is raised inside while the importlib.resources.path 
context manager is active a RuntimeError is raised.
Looking at the (3.8) code it seems that FileNotFound exceptions are handled 
specially from all other exceptions which may lead to this behaviour. While the 
code in 3.9 changed significantly the same behaviour can be observed.

└── my_package
    ├── data.txt (empty)
    ├── (empty)

Content of
import importlib.resources
def main():
    with importlib.resources.path('my_package', 'data.txt') as p:
        raise FileNotFoundError()
if __name__ == '__main__':

Exact error message:
RuntimeError: generator didn't stop after throw()

components: Library (Lib)
messages: 393686
nosy: Nils Kattenbeck, brett.cannon, jaraco
priority: normal
severity: normal
status: open
title: importlib.resources.path raises RuntimeError import FileNotFoundError is 
raise in context manager
type: behavior
versions: Python 3.8, Python 3.9

Python tracker <>
Python-bugs-list mailing list

Reply via email to