Almost every Python web framework has a simple server that runs a wsgi application and automatically reloads the imported modules every time the source gets changed. I know I can look at the code and see how it's done, but that may take some time and I'm asking just out of curiosity. Does anyone have any idea how this is implemented?

2 Answers

2
Armin Ronacher On Best Solutions

As the author of one of the reloader mechanisms (the one in werkzeug) I can tell you that it doesn't work. What all the reloaders do is forking one time and restarting the child process if a monitor thread notices that one module changed on the file system.

Inline reload()ing doesn't work because references to the reloaded module are not updated.

1
sanxiyn On

reload() does not work. "Reloading" is usually implemented by forking.

Implementing "real" reload() is extremely difficult and even the most serious attempt, twisted.python.rebuild isn't perfect.