##// END OF EJS Templates
Add option to %autoreload to hide errors when reloading code
Carlos Cordoba -
Show More
@@ -170,6 +170,9 b' class ModuleReloader:'
170 170 # Cache module modification times
171 171 self.check(check_all=True, do_reload=False)
172 172
173 # To hide autoreload errors
174 self.hide_errors = False
175
173 176 def mark_module_skipped(self, module_name):
174 177 """Skip reloading the named module in the future"""
175 178 try:
@@ -274,12 +277,13 b' class ModuleReloader:'
274 277 if py_filename in self.failed:
275 278 del self.failed[py_filename]
276 279 except:
277 print(
278 "[autoreload of {} failed: {}]".format(
279 modname, traceback.format_exc(10)
280 ),
281 file=sys.stderr,
282 )
280 if not self.hide_errors:
281 print(
282 "[autoreload of {} failed: {}]".format(
283 modname, traceback.format_exc(10)
284 ),
285 file=sys.stderr,
286 )
283 287 self.failed[py_filename] = pymtime
284 288
285 289
@@ -553,6 +557,12 b' class AutoreloadMagics(Magics):'
553 557 default=False,
554 558 help="Show autoreload activity using the logger",
555 559 )
560 @magic_arguments.argument(
561 "--hide-errors",
562 action="store_true",
563 default=False,
564 help="Hide autoreload errors",
565 )
556 566 def autoreload(self, line=""):
557 567 r"""%autoreload => Reload modules automatically
558 568
@@ -579,6 +589,9 b' class AutoreloadMagics(Magics):'
579 589 is to act silently; --print (or -p) will print out the names of modules that are being
580 590 reloaded, and --log (or -l) outputs them to the log at INFO level.
581 591
592 The optional argument --hide-errors hides any errors that can happen when trying to
593 reload code.
594
582 595 Reloading Python modules in a reliable way is in general
583 596 difficult, and unexpected things may occur. %autoreload tries to
584 597 work around common pitfalls by replacing function code objects and
@@ -628,6 +641,8 b' class AutoreloadMagics(Magics):'
628 641 elif args.log is True:
629 642 self._reloader._report = l
630 643
644 self._reloader.hide_errors = args.hide_errors
645
631 646 if mode == "" or mode == "now":
632 647 self._reloader.check(True)
633 648 elif mode == "0" or mode == "off":
General Comments 0
You need to be logged in to leave comments. Login now