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

Could not find source code file when running in Jupyter lab #101

Closed
aeryen opened this issue Sep 23, 2021 · 5 comments
Closed

Could not find source code file when running in Jupyter lab #101

aeryen opened this issue Sep 23, 2021 · 5 comments

Comments

@aeryen
Copy link
Contributor

aeryen commented Sep 23, 2021

Maybe it's me being silly but.

Symptom:
when running in jupyter lab the following command
%lprun -f some_function some_function()

Timer unit: 1e-06 s

Total time: 0.72679 s

Could not find file /tmp/xpython_38521/3689601706.py
Are you sure you are running this program from the same directory
that you ran the profiler from?
Continuing without the function's contents.

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    29                                           
    30         1          3.0      3.0      0.0  
    31                                           
    32         1        167.0    167.0      0.0  
    33         1         97.0     97.0      0.0  

So essentially it can't find a corresponding .py source code to match function content.

My environment is
ipykernel 6.4.0
ipython 7.27.0
jupyter-client 7.0.2
jupyter-core 4.7.1
jupyter-lsp 1.4.1
jupyter-server 1.11.0
jupyterlab 3.1.11
jupyterlab-lsp 3.8.1
jupyterlab-pygments 0.1.2
jupyterlab-server 2.8.1
jupyterlab-widgets 1.0.1
line-profiler 3.3.0

I'm using XEUS-Python 3.8, I've also tested with the regular ipykernel Python 3.8, also doesn't work.

The folder it's attempting to find, /tmp/xpython_38521 is not created in the first place.
However I notice that if i turn on jupyter lab debug mode , the folder will show up but the .py file is still not there.

I think yesterday when i first time used lprun it worked once!
However some how 5min later it stopped working.

@aeryen
Copy link
Contributor Author

aeryen commented Sep 23, 2021

I've tested a few more and try to make this replicable.
Reinstalled brand new miniconda, new virtual env, and tested in both jupyter-lab and jupyter-notebook.
process:

  1. Install latest miniconda
    https://docs.conda.io/en/latest/miniconda.html

  2. follow xeus-python instruction to install latest env
    https://github.com/jupyter-xeus/xeus-python
    conda install xeus-python notebook -c conda-forge

  3. install jupyter-lab and line-profiler

  4. profile with following

%load_ext line_profiler

def my_method():
    for i in range(20):
        print( "" + str(i) )

%lprun -f my_method my_method()

@Erotemic
Copy link
Member

It might be the same as #86 which was just published in 3.3.1. Try updating and check if your issue is fixed.

@aeryen
Copy link
Contributor Author

aeryen commented Sep 24, 2021

It might be the same as #86 which was just published in 3.3.1. Try updating and check if your issue is fixed.

The latest version 3.3.1 really does fixed it! Thanks!

However it still doesn't work very well with xeus-python, which seems to be less of an issue now that jupyter can debug using regular ipykernel.
But just in case you folks plan to support xeus, i'm guessing the issue is simply in this line:

filename.startswith(tempfile.gettempdir() + '/ipykernel_')

The xeus-python's temp folders are named like: /tmp/xpython_43854/72582958.py

@Erotemic
Copy link
Member

@aeryen Feel free to make a PR adding that check. I'm glad to unofficially support xeus if it is just a one line change (I really don't know much about what it is, I suppose a C++ re implementation of Jupyter?).

@aeryen
Copy link
Contributor Author

aeryen commented Sep 27, 2021

Hi thanks for letting me do that! I've just made a PR with one line change.
This is my first PR so let me know if i messd up somewhere!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants