Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hot reloading / swapping with Python [duplicate]

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

Edit:

After reading the pages linked by 'Ivo van der Wijk', I think it would be best to restart the web application when code changes - like Django does. So the actual question is: How to monitor file modifications?

like image 596
deamon Avatar asked Oct 05 '10 10:10

deamon


2 Answers

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

like image 51
Jesper Borgstrup Avatar answered Oct 13 '22 00:10

Jesper Borgstrup


This question has been asked a number of times

You can use reload(module) for this, but beware of nasty side effects. For example, existing code will be based on the original code, it will not magically get new attributes or baseclasses added.

like image 35
Ivo van der Wijk Avatar answered Oct 13 '22 01:10

Ivo van der Wijk