Show More
@@ -252,6 +252,9 b" def autoreload_f(self, parameter_s=''):" | |||
|
252 | 252 | %autoreload |
|
253 | 253 | Reload all modules (except those excluded by %aimport) automatically now. |
|
254 | 254 | |
|
255 | %autoreload 0 | |
|
256 | Disable automatic reloading. | |
|
257 | ||
|
255 | 258 | %autoreload 1 |
|
256 | 259 | Reload all modules imported with %aimport every time before executing |
|
257 | 260 | the Python code typed. |
@@ -260,14 +263,15 b" def autoreload_f(self, parameter_s=''):" | |||
|
260 | 263 | Reload all modules (except those excluded by %aimport) every time |
|
261 | 264 | before executing the Python code typed. |
|
262 | 265 | |
|
263 |
Reloading Python modules in a reliable way is in general |
|
|
264 |
and unexpected things may occur. %autoreload tries to |
|
|
265 |
around common pitfalls by replacing code objects |
|
|
266 |
previously in the module with new versions. This |
|
|
267 | things to work: | |
|
266 | Reloading Python modules in a reliable way is in general | |
|
267 | difficult, and unexpected things may occur. %autoreload tries to | |
|
268 | work around common pitfalls by replacing function code objects and | |
|
269 | parts of classes previously in the module with new versions. This | |
|
270 | makes the following things to work: | |
|
268 | 271 | |
|
269 | 272 | - Functions and classes imported via 'from xxx import foo' are upgraded |
|
270 | 273 | to new versions when 'xxx' is reloaded. |
|
274 | ||
|
271 | 275 | - Methods and properties of classes are upgraded on reload, so that |
|
272 | 276 | calling 'c.foo()' on an object 'c' created before the reload causes |
|
273 | 277 | the new code for 'foo' to be executed. |
@@ -277,8 +281,10 b" def autoreload_f(self, parameter_s=''):" | |||
|
277 | 281 | - Replacing code objects does not always succeed: changing a @property |
|
278 | 282 | in a class to an ordinary method or a method to a member variable |
|
279 | 283 | can cause problems (but in old objects only). |
|
284 | ||
|
280 | 285 | - Functions that are removed (eg. via monkey-patching) from a module |
|
281 | 286 | before it is reloaded are not upgraded. |
|
287 | ||
|
282 | 288 | - C extension modules cannot be reloaded, and so cannot be |
|
283 | 289 | autoreloaded. |
|
284 | 290 | |
@@ -329,8 +335,11 b" def aimport_f(self, parameter_s=''):" | |||
|
329 | 335 | except KeyError: pass |
|
330 | 336 | reloader.modules[modname] = True |
|
331 | 337 | |
|
332 | mod = __import__(modname) | |
|
333 |
|
|
|
338 | # Inject module to user namespace; handle also submodules properly | |
|
339 | __import__(modname) | |
|
340 | basename = modname.split('.')[0] | |
|
341 | mod = sys.modules[basename] | |
|
342 | ip.to_user_ns({basename: mod}) | |
|
334 | 343 | |
|
335 | 344 | def init(): |
|
336 | 345 | ip.expose_magic('autoreload', autoreload_f) |
General Comments 0
You need to be logged in to leave comments.
Login now