title: import side effects on logging: how to reset the logging module?
body: <p>Consider this code:</p>
  
  <pre><code>import logging
  print "print"
  logging.error("log")
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>print
  ERROR:root:log
  </code></pre>
  
  <p>now if I include a thid-party module at the beginning of the previous code and rerun it I get only:</p>
  
  <pre><code>print
  </code></pre>
  
  <p>there are some previous question about this, but here I cannot touch the module I'm importing.</p>
  
  <p>The code of the third-party module is here: <a href="http://atlas-sw.cern.ch/cgi-bin/viewcvs-atlas.cgi/offline/DataManagement/DQ2/dq2.clientapi/lib/dq2/clientapi/DQ2.py?view=markup">http://atlas-sw.cern.ch/cgi-bin/viewcvs-atlas.cgi/offline/DataManagement/DQ2/dq2.clientapi/lib/dq2/clientapi/DQ2.py?view=markup</a>, but my question is more general: independently of the module I'm importing I want a clean <code>logging</code> working in the expected way</p>
  
  <p><strong>Some (non-working) proposed solutions:</strong></p>
  
  <pre><code>from dq2.clientapi.DQ2 import DQ2
  import logging
  del logging.root.handlers[:]
  </code></pre>
  
  <hr>
  
  <pre><code>from dq2.clientapi.DQ2 import DQ2
  import logging
  logging.disable(logging.NOTSET)
  </code></pre>
  
  <hr>
  
  <pre><code>logs = logging.getLogger('root')
  logs.error("Some error")
  </code></pre>
  
  <hr>
  
  <p>the next one works, but produced some additional errors:</p>
  
  <pre><code>from dq2.clientapi.DQ2 import DQ2
  import logging
  reload(logging)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>print
  ERROR:root:log
  Error in atexit._run_exitfuncs:
  Traceback (most recent call last):
    File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-    opt/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
      func(*targs, **kargs)
    File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 1509, in shutdown
      h.close()
    File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 705, in close
      del _handlers[self]
  KeyError: &lt;logging.StreamHandler instance at 0x2aea031f7248&gt;
  Error in sys.exitfunc:
  Traceback (most recent call last):
    File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
      func(*targs, **kargs)
    File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 1509, in shutdown
      h.close()
    File "/afs/cern.ch/sw/lcg/external/Python/2.6.5/x86_64-slc5-gcc43-opt/lib/python2.6/logging/__init__.py", line 705, in close
      del _handlers[self]
  KeyError: &lt;logging.StreamHandler instance at 0x2aea031f7248&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>from dq2.clientapi.DQ2 import DQ2
  import logging
  logger = logging.getLogger(__name__)
  ch = logging.StreamHandler()  
  logger.addHandler(ch)
  logger.error("log")
  </code></pre>