Show More
@@ -27,6 +27,7 b' try:' | |||||
27 | from signal import SIGKILL |
|
27 | from signal import SIGKILL | |
28 | except ImportError: |
|
28 | except ImportError: | |
29 | SIGKILL=None |
|
29 | SIGKILL=None | |
|
30 | from types import FunctionType | |||
30 |
|
31 | |||
31 | try: |
|
32 | try: | |
32 | import cPickle |
|
33 | import cPickle | |
@@ -221,8 +222,16 b' def interactive(f):' | |||||
221 | This results in the function being linked to the user_ns as globals() |
|
222 | This results in the function being linked to the user_ns as globals() | |
222 | instead of the module globals(). |
|
223 | instead of the module globals(). | |
223 | """ |
|
224 | """ | |
224 |
|
|
225 | mainmod = __import__('__main__') | |
225 | return f |
|
226 | ||
|
227 | # build new FunctionType, so it can have the right globals | |||
|
228 | # interactive functions never have closures, that's kind of the point | |||
|
229 | f2 = FunctionType(f.__code__, mainmod.__dict__, | |||
|
230 | f.__name__, f.__defaults__, | |||
|
231 | ) | |||
|
232 | # associate with __main__ for uncanning | |||
|
233 | f2.__module__ = '__main__' | |||
|
234 | return f2 | |||
226 |
|
235 | |||
227 | @interactive |
|
236 | @interactive | |
228 | def _push(**ns): |
|
237 | def _push(**ns): |
General Comments 0
You need to be logged in to leave comments.
Login now