title: Initialize module only once on imports from multiple files
body: <p>I have multiple python scripts, like this:</p>
  <ul>
  <li>utils.py</li>
  <li>module1.py</li>
  <li>module2.py</li>
  <li>module3.py</li>
  <li>main.py</li>
  <li>...</li>
  </ul>
  <p>In utils.py:</p>
  <pre class="lang-py prettyprint-override"><code>import some_lib
  role_id = &quot;some_key_1&quot;
  secret_id = &quot;some_key_2&quot;
  
  def initialize():
      real_key = some_web_request(role_id, secret_id)
      some_lib.init(real_key)
  
  # define some other functions using some_lib
  </code></pre>
  <p>In module1.py, module2.py, module3.py:</p>
  <pre class="lang-py prettyprint-override"><code>import utils
  
  # define some other functions using functions in utils.py
  </code></pre>
  <p>In main.py:</p>
  <pre class="lang-py prettyprint-override"><code>import module1
  import module2
  import module3
  
  # do something
  </code></pre>
  <p>I want to run utils.initialize() only once for initializing <code>some_lib</code>. However, due to how <code>import</code> works in python, if I put initialize() on global area in utils.py then it will run on every import statement run.</p>
  <p>I can implement this like this, in utils.py</p>
  <pre class="lang-py prettyprint-override"><code>import some_lib
  
  initialized = False
  
  def initialize():
      # same as above
  
  if not initialized:
      initialize()
      initialized = True
  </code></pre>
  <p>Is this a good practice? Is there better or elegant way to implement this?</p>