Hot reboot / exchange with Python

I want the code changes to take effect immediately during development. How can I detect modified files and reload them in a running Python application (2.7)?

Edit:

After reading the pages related to "Ivo van der Wijk", I think it would be better to restart the web application when changing the code - for example, Django. So, the actual question: How to track file changes?

+3
source share
3 answers

This question has been asked <a href = "> a number of times

You can use a reboot (module) for this, but beware of unpleasant side effects. For example, existing code will be based on the source code; it will not magically add new attributes or base points.

+3
source

I wanted to get the same effect for some of my Python scripts, so I continued working and made the SourceChangeMonitor.py script. You can find it with instructions here . If you just want a script, here is a direct link

+6
source

This does not make sense for most applications because you will get side effects using reload . In addition, the time spent on code that detects changes and reloads all modules can be spent simply restarting the application. This is very difficult if you import a lot of modules or have a project that contains many submodules.

In some cases, this is a good idea. The Django web environment provides a development server ( manage.py runserver ) that automatically reloads the changed modules. Take a look at django.utils.autoreload - it checks all Python files for changes using file modification time. As already mentioned, this is only a good idea for some applications. Web applications are somewhat stateless and therefore can be reloaded with minor side effects.

+2
source

All Articles