##// END OF EJS Templates
Very small changes to %run for tracking an ongoing problem....
Fernando Perez -
Show More
@@ -1422,7 +1422,8 b' Currently the magic system has the following functions:\\n"""'
1422 return None
1422 return None
1423
1423
1424 @testdec.skip_doctest
1424 @testdec.skip_doctest
1425 def magic_run(self, parameter_s ='',runner=None):
1425 def magic_run(self, parameter_s ='',runner=None,
1426 file_finder=get_py_filename):
1426 """Run the named file inside IPython as a program.
1427 """Run the named file inside IPython as a program.
1427
1428
1428 Usage:\\
1429 Usage:\\
@@ -1537,7 +1538,7 b' Currently the magic system has the following functions:\\n"""'
1537 mode='list',list_all=1)
1538 mode='list',list_all=1)
1538
1539
1539 try:
1540 try:
1540 filename = get_py_filename(arg_lst[0])
1541 filename = file_finder(arg_lst[0])
1541 except IndexError:
1542 except IndexError:
1542 warn('you must provide at least a filename.')
1543 warn('you must provide at least a filename.')
1543 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1544 print '\n%run:\n',OInspect.getdoc(self.magic_run)
@@ -1573,11 +1574,29 b' Currently the magic system has the following functions:\\n"""'
1573 main_mod = FakeModule()
1574 main_mod = FakeModule()
1574 prog_ns = main_mod.__dict__
1575 prog_ns = main_mod.__dict__
1575 prog_ns['__name__'] = name
1576 prog_ns['__name__'] = name
1577
1576 # The shell MUST hold a reference to main_mod so after %run exits,
1578 # The shell MUST hold a reference to main_mod so after %run exits,
1577 # the python deletion mechanism doesn't zero it out (leaving
1579 # the python deletion mechanism doesn't zero it out (leaving
1578 # dangling references)
1580 # dangling references)
1581
1582 # XXX - the note above was written without further detail, but this
1583 # code actually causes problems. By holding references to the
1584 # namespace where every script is executed, we effectively disable
1585 # just about all possible variable cleanup. In particular,
1586 # generator expressions and other variables that point to open
1587 # files are kept alive, and as a user session lives on, it may run
1588 # out of available file descriptors. Such a bug has already been
1589 # reported by JD Hunter. I'm disabling this for now, but we need
1590 # to clarify exactly (and add tests) what from main_mod needs to be
1591 # kept alive and what is save to remove... In fact, see note
1592 # below, where we append main_mod to sys.modules and then delete it
1593 # again. The final cleanup is rendered moot by this reference kept
1594 # in _user_main_modules(), so we really need to look into this.
1595
1579 self.shell._user_main_modules.append(main_mod)
1596 self.shell._user_main_modules.append(main_mod)
1580
1597
1598 # /XXX
1599
1581 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1600 # Since '%run foo' emulates 'python foo.py' at the cmd line, we must
1582 # set the __file__ global in the script's namespace
1601 # set the __file__ global in the script's namespace
1583 prog_ns['__file__'] = filename
1602 prog_ns['__file__'] = filename
General Comments 0
You need to be logged in to leave comments. Login now