title: Deep Reload Modules from only One Package
body: <p>How do you deep reload a package without importing modules from any other outside packages?</p>
  
  <p>For example, for reloading the following:</p>
  
  <pre><code># example_pkg.py
  import logging  # do not reload this stdlib package
  import example_pkg.ex_mod  # reload this module
  </code></pre>
  
  <p>IPython's <a href="https://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.deepreload.html" rel="nofollow noreferrer"><code>deepreload</code></a> module cannot specify a whitelist for imports and uses module level variables during reloads which makes it unreliable for threaded environments.</p>
  
  <p>A question similar to this has been asked <a href="https://stackoverflow.com/questions/15506971/recursive-version-of-reload">before</a>, but it focused on discovering dependencies (as was <a href="https://stackoverflow.com/questions/15506971/recursive-version-of-reload#comment21958372_15506971">mentioned</a> in a comment) not exclusively within a single package.</p>