Skip to content

get_func_name returns across-session fluctuating names in Jupyter notebook with updated ipykernel  #1210

@mjziebarth

Description

@mjziebarth

Hello,

after a recent system update, I noticed that Memory-annotated functions defined within a Jupyter notebook
would be called after kernel restarts even though the arguments passed were the same across runs. This has worked without problems in the months before.

After some investigation, I think I pinpointed the underlying issue to be a possible naming scheme change in IPython that is not caught by the check in line 130 of func_inspect.py. If I am not mistaken, this function expects to see the name of the source file containing the function to contain <ipython-input. Instead, on my machine the structure of the source file path is /tmp/ipykernel_XXXXXXX/YYYYYYYYYY.py where the X are digits that change slightly on kernel restart and the Y seem to be a stable identifier of the source (at least I have not seen a variance there so far). Consequently, the check in parts[-1] does not work any more to condense a run-agnostic source identifier.

I have fixed the issue on my machine by inserting another case in get_func_name (see my fork). If wanted, I can create a PR, although I have limited resources at the moment to check the fix on other machines (or in non-Jupyter use cases).

Best
Malte

PS: I work on an Arch linux system and the Jupyter notebook gives the following version information:

Python 3.9.6
IPython 7.26.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions