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