##// END OF EJS Templates
Capture local scope for %time, so that it can be used for code inside functions.
Thomas Kluyver -
Show More
@@ -22,6 +22,7 b' import __future__'
22 22 import abc
23 23 import atexit
24 24 import codeop
25 import inspect
25 26 import os
26 27 import re
27 28 import sys
@@ -1727,6 +1728,10 b' class InteractiveShell(Configurable, Magic):'
1727 1728 valid Python code you can type at the interpreter, including loops and
1728 1729 compound statements.
1729 1730 """
1731 # Save the scope of the call so magic functions like %time can
1732 # evaluate expressions in it.
1733 self._magic_locals = inspect.stack()[1][0].f_locals
1734
1730 1735 args = arg_s.split(' ',1)
1731 1736 magic_name = args[0]
1732 1737 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
@@ -1928,17 +1928,18 b' Currently the magic system has the following functions:\\n"""'
1928 1928 tc = clock()-t0
1929 1929 # skew measurement as little as possible
1930 1930 glob = self.shell.user_ns
1931 locs = self._magic_locals
1931 1932 clk = clock2
1932 1933 wtime = time.time
1933 1934 # time execution
1934 1935 wall_st = wtime()
1935 1936 if mode=='eval':
1936 1937 st = clk()
1937 out = eval(code,glob)
1938 out = eval(code, glob, locs)
1938 1939 end = clk()
1939 1940 else:
1940 1941 st = clk()
1941 exec code in glob
1942 exec code in glob, locs
1942 1943 end = clk()
1943 1944 out = None
1944 1945 wall_end = wtime()
General Comments 0
You need to be logged in to leave comments. Login now