title: Python 2.7 runtime code changes
body: <p>for my Master Thesis, I'm trying to leverage Python's nature of being a scripting language in order to allow runtime changes of the source code. The source code itself is modelled using a special user interface and generated on save. On start, the generated code is sent to the engine and imported. This process works fine until the source code changes without restarting the engine between two runs (but restarting is no option).</p>
  
  <p>The problem is that the engine still holds a reference to the old source code even though the file has been changed.</p>
  
  <p>I spent quite some time searching for solutions and found <em>reload()</em> as one option (<a href="https://stackoverflow.com/questions/2534480/proper-way-to-reload-a-python-module-from-the-console">ref</a>). Unfortunately, this doesn't work for some reason. Here is the current version of the relevant part (executed each time source code changes are received):</p>
  
  <pre><code>package = __import__("tmp", fromlist=["tmp"])
  reload(package) # this seems to have no effect
  clsmembers = inspect.getmembers(package, lambda member: inspect.isclass(member) and member.__module__ == package.__name__)
  beclass = clsmembers[0][1]
  be = beclass()
  </code></pre>
  
  <p>I'm working with Python 2.7 (I have to, I know later Python versions offer better support for this feature). It doesn't have to be <em>reload()</em>, I just need any way to re-import the code changes.</p>
  
  <p>Any help is appreciated! :)</p>