MCPcopy Create free account
hub / github.com/ipython/ipython / autoreload

Method autoreload

IPython/extensions/autoreload.py:434–487  ·  view source on GitHub ↗

r"""%autoreload => Reload modules automatically %autoreload Reload all modules (except those excluded by %aimport) automatically now. %autoreload 0 Disable automatic reloading. %autoreload 1 Reload all modules imported with %aimport every ti

(self, parameter_s='')

Source from the content-addressed store, hash-verified

432
433 @line_magic
434 def autoreload(self, parameter_s=''):
435 r"""%autoreload => Reload modules automatically
436
437 %autoreload
438 Reload all modules (except those excluded by %aimport) automatically
439 now.
440
441 %autoreload 0
442 Disable automatic reloading.
443
444 %autoreload 1
445 Reload all modules imported with %aimport every time before executing
446 the Python code typed.
447
448 %autoreload 2
449 Reload all modules (except those excluded by %aimport) every time
450 before executing the Python code typed.
451
452 Reloading Python modules in a reliable way is in general
453 difficult, and unexpected things may occur. %autoreload tries to
454 work around common pitfalls by replacing function code objects and
455 parts of classes previously in the module with new versions. This
456 makes the following things to work:
457
458 - Functions and classes imported via 'from xxx import foo' are upgraded
459 to new versions when 'xxx' is reloaded.
460
461 - Methods and properties of classes are upgraded on reload, so that
462 calling 'c.foo()' on an object 'c' created before the reload causes
463 the new code for 'foo' to be executed.
464
465 Some of the known remaining caveats are:
466
467 - Replacing code objects does not always succeed: changing a @property
468 in a class to an ordinary method or a method to a member variable
469 can cause problems (but in old objects only).
470
471 - Functions that are removed (eg. via monkey-patching) from a module
472 before it is reloaded are not upgraded.
473
474 - C extension modules cannot be reloaded, and so cannot be
475 autoreloaded.
476
477 """
478 if parameter_s == '':
479 self._reloader.check(True)
480 elif parameter_s == '0':
481 self._reloader.enabled = False
482 elif parameter_s == '1':
483 self._reloader.check_all = False
484 self._reloader.enabled = True
485 elif parameter_s == '2':
486 self._reloader.check_all = True
487 self._reloader.enabled = True
488
489 @line_magic
490 def aimport(self, parameter_s='', stream=None):

Callers 1

magic_autoreloadMethod · 0.80

Calls 1

checkMethod · 0.45

Tested by 1

magic_autoreloadMethod · 0.64