Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect.getouterframes() tracebacks when $CWD does not exists #89569

Closed
msuchyredhatcom mannequin opened this issue Oct 7, 2021 · 7 comments
Closed

inspect.getouterframes() tracebacks when $CWD does not exists #89569

msuchyredhatcom mannequin opened this issue Oct 7, 2021 · 7 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@msuchyredhatcom
Copy link
Mannequin

msuchyredhatcom mannequin commented Oct 7, 2021

BPO 45406
Nosy @ambv, @raulcd, @miss-islington, @iritkatriel
PRs
  • bpo-45406: make inspect.getmodule() return None when getabsfile() rai… #28824
  • [3.10] bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824) #29377
  • [3.9] bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824) #29378
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-11-02.23:15:32.429>
    created_at = <Date 2021-10-07.13:57:49.324>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'inspect.getouterframes() tracebacks when $CWD does not exists'
    updated_at = <Date 2021-11-02.23:15:32.428>
    user = 'https://bugs.python.org/msuchyredhatcom'

    bugs.python.org fields:

    activity = <Date 2021-11-02.23:15:32.428>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-11-02.23:15:32.429>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2021-10-07.13:57:49.324>
    creator = 'msuchy@redhat.com'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45406
    keywords = ['patch']
    message_count = 7.0
    messages = ['403410', '403461', '403491', '405560', '405563', '405565', '405567']
    nosy_count = 5.0
    nosy_names = ['lukasz.langa', 'msuchy@redhat.com', 'raulcd', 'miss-islington', 'iritkatriel']
    pr_nums = ['28824', '29377', '29378']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45406'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @msuchyredhatcom
    Copy link
    Mannequin Author

    msuchyredhatcom mannequin commented Oct 7, 2021

    When you exec inspect.getouterframes() in directory, which no longer exists, then you get traceback, because the code traverse to os.getcwd() which fails.

    Reproducer:

    $ mkdir /tmp/bar
    $ cd /tmp/bar
    $ rmdir /tmp/bar
    $ python3
    Python 3.10.0rc2 (default, Sep  8 2021, 00:00:00) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import inspect
    >>> inspect.getouterframes(inspect.currentframe())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python3.10/inspect.py", line 1653, in getouterframes
        frameinfo = (frame,) + getframeinfo(frame, context)
      File "/usr/lib64/python3.10/inspect.py", line 1623, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/usr/lib64/python3.10/inspect.py", line 829, in getsourcefile
        module = getmodule(object, filename)
      File "/usr/lib64/python3.10/inspect.py", line 861, in getmodule
        file = getabsfile(object, _filename)
      File "/usr/lib64/python3.10/inspect.py", line 845, in getabsfile
        return os.path.normcase(os.path.abspath(_filename))
      File "/usr/lib64/python3.10/posixpath.py", line 383, in abspath
        cwd = os.getcwd()
    FileNotFoundError: [Errno 2] No such file or directory

    @msuchyredhatcom msuchyredhatcom mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 7, 2021
    @raulcd
    Copy link
    Mannequin

    raulcd mannequin commented Oct 8, 2021

    I have reproduced on python3.10 and validated this is also happening for other python versions:

    # PYTHON 3.9
    $ mkdir /tmp/bar
    $ cd /tmp/bar
    $ rmdir /tmp/bar
    $ python3.9
    Python 3.9.5 (default, May 19 2021, 11:32:47) 
    [GCC 9.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import inspect
    >>> inspect.getouterframes(inspect.currentframe())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.9/inspect.py", line 1529, in getouterframes
        frameinfo = (frame,) + getframeinfo(frame, context)
      File "/usr/lib/python3.9/inspect.py", line 1499, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/usr/lib/python3.9/inspect.py", line 709, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/usr/lib/python3.9/inspect.py", line 738, in getmodule
        file = getabsfile(object, _filename)
      File "/usr/lib/python3.9/inspect.py", line 722, in getabsfile
        return os.path.normcase(os.path.abspath(_filename))
      File "/usr/lib/python3.9/posixpath.py", line 379, in abspath
        cwd = os.getcwd()
    FileNotFoundError: [Errno 2] No such file or directory
    
    # PYTHON 3.8
    $ mkdir /tmp/bar
    $ cd /tmp/bar
    $ rmdir /tmp/bar
    $ python3.8
    Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
    [GCC 9.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import inspect
    >>> inspect.getouterframes(inspect.currentframe())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.8/inspect.py", line 1503, in getouterframes
        frameinfo = (frame,) + getframeinfo(frame, context)
      File "/usr/lib/python3.8/inspect.py", line 1473, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/usr/lib/python3.8/inspect.py", line 708, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/usr/lib/python3.8/inspect.py", line 737, in getmodule
        file = getabsfile(object, _filename)
      File "/usr/lib/python3.8/inspect.py", line 721, in getabsfile
        return os.path.normcase(os.path.abspath(_filename))
      File "/usr/lib/python3.8/posixpath.py", line 379, in abspath
        cwd = os.getcwd()
    FileNotFoundError: [Errno 2] No such file or directory
    Error in sys.excepthook:
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 76, in apport_excepthook
        binary = os.path.realpath(os.path.join(os.getcwd(), sys.argv[0]))
    FileNotFoundError: [Errno 2] No such file or directory
    
    Original exception was:
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.8/inspect.py", line 1503, in getouterframes
        frameinfo = (frame,) + getframeinfo(frame, context)
      File "/usr/lib/python3.8/inspect.py", line 1473, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/usr/lib/python3.8/inspect.py", line 708, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/usr/lib/python3.8/inspect.py", line 737, in getmodule
        file = getabsfile(object, _filename)
      File "/usr/lib/python3.8/inspect.py", line 721, in getabsfile
        return os.path.normcase(os.path.abspath(_filename))
      File "/usr/lib/python3.8/posixpath.py", line 379, in abspath
        cwd = os.getcwd()
    FileNotFoundError: [Errno 2] No such file or directory
    >>>

    @iritkatriel
    Copy link
    Member

    Thanks for the report, crash typically refers to segfaults rather than exceptions being raised. Updated versions.

    @iritkatriel iritkatriel added 3.9 only security fixes 3.11 only security fixes type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 8, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Nov 2, 2021

    New changeset a459a81 by Irit Katriel in branch 'main':
    bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824)
    a459a81

    @miss-islington
    Copy link
    Contributor

    New changeset cfdd7d2 by Miss Islington (bot) in branch '3.10':
    bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824)
    cfdd7d2

    @miss-islington
    Copy link
    Contributor

    New changeset 5f527ca by Miss Islington (bot) in branch '3.9':
    bpo-45406: make inspect.getmodule() return None when getabsfile() raises FileNotFoundError (GH-28824)
    5f527ca

    @iritkatriel
    Copy link
    Member

    Thanks Lukasz.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants