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