title: Detect if a python module changes and then reload
body: <p>So I'm developing a rather large python project with a number of modules. The "main" (runnable) module is a daemon (a Thrift daemon, actually) which calls off to other modules for its actual functionality. Starting up the daemon takes a long time because some of the modules have a rather lengthy and involved initialization processes.</p>
  
  <p>So when I start the daemon, I wait... let's say... 2 minutes for everything to load, which isn't too bad in the grand scheme of things. However for development it becomes a major pain because I need to restart the daemon EVERY TIME which has been wasting a lot of my time.</p>
  
  <p>Most modules only takes a few seconds to load. Ideally what I'd like to do is detect when any of the files in a particular module have changed, and reload that particular module. I've already figured out <a href="https://stackoverflow.com/questions/4111640/how-to-reimport-module-to-python-then-code-be-changed-after-import">how to reload a module</a>, but at this point I can't figure out how to watch a particular module for changes. Keep in mind that a module isn't a single <code>.py</code> file in this case, but rather a directory with <code>__init__.py</code> and 5-10 <code>.py</code> files, so I need to detect when <em>any</em> of them have changed.</p>
  
  <p>Here is the project layout (if it makes any difference at all)</p>
  
  <pre><code>project
  | -- daemonize.py
  | -- main.py
  | -- moduleA
  |    | -- __init__.py
  |    | -- happy_panda.py
  |    ` -- sad_panda.py
  | -- moduleB
  |    | -- __init__.py
  |    | -- takes_forever_to_load.py
  |    ` -- seriously_get_some_coffee.py
  | -- moduleC
  |    | -- __init__.py
  |    | -- frequently_changes.py
  |    | -- reasons_i_hate_my_job.txt
  |    ` -- home_address_of_moduleB_developer.txt
  ` -- service.py &lt;-- uses modules A, B, and C
  </code></pre>
  
  <p>Any ideas or suggestions are appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks for the great feedback. Here is the code I created based on the suggestions. There's a small bug where pyinotify seems to be getting more than one notification, but it's a very small problem for me so I'm not going to fix it.</p>
  
  <p><a href="https://gist.github.com/1013122" rel="noreferrer">https://gist.github.com/1013122</a></p>