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

Magic function %prun not printing #3119

Closed
LowArmour opened this issue Sep 9, 2019 · 10 comments
Closed

Magic function %prun not printing #3119

LowArmour opened this issue Sep 9, 2019 · 10 comments

Comments

@LowArmour
Copy link

Hi,

I have tried for several hours multiple examples, it seems i can't get the magic function %prun to print its output.
When I run it, it seems it is working and after it is finished, it does not print the related output.
My pip list is:
Package Version


astroid 2.2.5
attrs 19.1.0
backcall 0.1.0
bleach 3.1.0
Cython 0.29.13
decorator 4.4.0
defusedxml 0.6.0
entrypoints 0.3
ipykernel 5.1.2
ipython 7.8.0
ipython-genutils 0.2.0
ipywidgets 7.5.1
isort 4.3.21
jedi 0.15.1
Jinja2 2.10.1
jsonschema 3.0.2
jupyter 1.0.0
jupyter-client 5.3.1
jupyter-console 6.0.0
jupyter-core 4.5.0
lazy-object-proxy 1.4.2
MarkupSafe 1.1.1
mccabe 0.6.1
mistune 0.8.4
nbconvert 5.6.0
nbformat 4.4.0
notebook 6.0.1
numpy 1.17.2
packaging 19.1
pandas 0.25.1
pandocfilters 1.4.2
parso 0.5.1
pexpect 4.7.0
pickleshare 0.7.5
pip 19.2.3
pip-review 1.0
prometheus-client 0.7.1
prompt-toolkit 2.0.9
ptyprocess 0.6.0
Pygments 2.4.2
pylint 2.3.1
pymongo 3.9.0
pyparsing 2.4.2
pyrsistent 0.15.4
python-dateutil 2.8.0
pytz 2019.2
pyzmq 18.1.0
qtconsole 4.5.5
Send2Trash 1.5.0
setuptools 41.2.0
six 1.12.0
terminado 0.8.2
testpath 0.4.2
tornado 6.0.3
traitlets 4.3.2
typed-ast 1.4.0
wcwidth 0.1.7
webencodings 0.5.1
widgetsnbextension 3.5.1
wrapt 1.11.2

Also the related screenshot with the code cell and my attempts:
Screenshot from 2019-09-09 14-43-07

Many thanks in advance!

EDIT:
Copy pasted the code from the screenshot for ease of reference (the code is an example from the web testing the %prun magic function: http://gouthamanbalaraman.com/blog/profiling-python-jupyter-notebooks.html ):
import numpy as np

def func(n, a):
y = np.arange(n)
y = np.exp(-y*a)
return y

def gunc(n, a):
y = np.exp(-n*a)
return y

def hunc(n, a):
y1 = func(n, a)
y2 = gunc(n, a)
return y1, y2

@ARF1
Copy link

ARF1 commented Sep 9, 2019

I encountered the same problem. The issue seems to be that jupyter does not output the result of %prun as a usual cell but in a separate frame/window. It seems, vscode does not catch this unusual type of jupyter output.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 10, 2019

Thanks @ARF1, if Jupyter doesn't output a cell that would be why prun doesn't have any output. We currently only show cell based output.

@ARF1
Copy link

ARF1 commented Sep 10, 2019

@rchiodo It would be really great if you could manage to capture these "output frames".

Quick profiling with %prun and interactive drill down in a profiled call stack with %snakeviz are really great solutions to problems that are awkward to solve otherwise. (You need to keep modifying your source file which gets really messy.)

Attached is an example of the jupyter display. See the "frame/window" that has popped up on the lower half of the screen which partially obscures the unscrolled "normal jupyter window/frame". Note this is not a separate browser tab or window but a <div>.

From what I can tell, jupyter call this "pager" messages/output. See also the %page magic

image

@rchiodo
Copy link
Contributor

rchiodo commented Sep 10, 2019

Hmm, not sure that's possible at the moment. Might require changes to the jupyter api. We don't get any pager results through their web api. We get a single stream output with nothing in it.

@ARF1
Copy link

ARF1 commented Sep 10, 2019

@rchiodo Apologies, I found the solution already. At first glance it appears trivial:

import IPython.core
IPython.core.page = print

After running this, all pager output appears in normal output cells.

It might be worth sending this automatically to jupyter when a kernel is started/restarted.

@rchiodo
Copy link
Contributor

rchiodo commented Sep 10, 2019

Sweet, thanks a bunch, that's likely what we'll do. We already have a bunch of stuff we run at startup.

@rickhg12hs
Copy link

@ARF1 Do you know of a solution for printing magic help outputs? For example, %lsmagic doesn't show anything even after your IPython.core.page = print trick.

@ARF1
Copy link

ARF1 commented Sep 17, 2019

@rickhg12hs Sorry no. Might be a question to ask the jupyter project though with a new issue...

@greazer
Copy link
Member

greazer commented Oct 18, 2019

dupe of microsoft/vscode-python#6900

@greazer greazer closed this as completed Oct 18, 2019
@Axel-Shark
Copy link

@ARF1 Do you know of a solution for printing magic help outputs? For example, %lsmagic doesn't show anything even after your IPython.core.page = print trick.

Same. Doesn't appear to have any effect on magic commands of using ? for help.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 30, 2019
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants