4

I am going through a book on Python which spends a decent time on module reloading, but does not explain well when it would be useful.

Hence, I am wondering, what are some real-life examples of when such technique becomes handy?

That is, I understand what reloading does. I am trying to understand how one would use it in real world.

Edit:

I am not suggesting that this technique is not useful. Instead, I am trying to learn more about its applications as it seems quite cool.

Also, I think people who marked this question as duplicate took no time to actually read the question and how it is different from the proposed duplicate. I am not asking HOW TO reload a module in Python. I already know how to do that. I am asking WHY one would want to reload a module in Python in real life. There is a huge difference in nature of these questions.

MadPhysicist
  • 5,401
  • 11
  • 42
  • 107
  • 1
    Apparently this person needed it: https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module – JHS Aug 04 '17 at 18:19
  • I mean using the `from imp import reload` and doing something like `reload(module_name)` – MadPhysicist Aug 04 '17 at 18:20
  • 1
    @MadPhysicist Yes, I know. I just realized that. I (mistakenly) thought you were asking [this question](https://stackoverflow.com/questions/19077381/what-happens-when-i-import-module-twice-in-python). – Christian Dean Aug 04 '17 at 18:21
  • @ChristianDean no problem. – MadPhysicist Aug 04 '17 at 18:24
  • 2
    The question is about _why_ to do reloading, not _how_ to do reloading. I do not see how it is a duplicate. I propose to reopen it. – DYZ Aug 04 '17 at 21:56
  • @DYZ precisely! Whoever marked it as duplicate clearly misread or misunderstood the question! – MadPhysicist Aug 04 '17 at 23:20

2 Answers2

3

Module reloading (also known as "hot-swapping") is commonly used in long-running systems, such as telephone switch software, that cannot be shut down for maintenance without causing costly service interruption. Such systems are upgraded piece-wise, one module at a time. For example, hot-swapping is natively supported at the implementation level by Erlang.

Python systems rarely run for long time. Real-life module reloading in Python does not seem to be of major importance.

EDIT: As @Aaron suggested, module reloading is used in some Python IDEs to facilitate module development.

DYZ
  • 55,249
  • 10
  • 64
  • 93
  • 1
    Some IDEs (spyder) provide module re-loading mechanisms within their shell to make developing those modules easier. – Aaron Aug 04 '17 at 18:27
  • 1
    @Aaron True. I interpreted "real-life" as "industrial use." One may argue forever if this includes IDEs. – DYZ Aug 04 '17 at 18:29
  • This is an overly simplistic and a little narrow. There are plenty of reasons to reload modules Django is a splendid example of long-running web servers that require it. See the duplicate answer for more detail – msw Aug 04 '17 at 21:50
0

As an appendix to DYZ's answer, I use module reloading when analysing large data in interactive Python interpreter.

Loading and preprocessing of the data takes some time and I prefer to keep them in the memory (in a module BTW) rather than restart the interpreter every time I change something in my modules.

abukaj
  • 2,582
  • 1
  • 22
  • 45