Skip to content Skip to sidebar Skip to footer

Python Reload Module Does Not Take Effect Immediately

see the reproduction code below. Tracing a memory leak I found that reload(module) does not immediately take effect. The program below should print 0,1,2,3,4 but, when executed fas

Solution 1:

The problem is that a pyc won't regenerate unless it is out-of-date with respect to the undelying py file. If the file modification times are checked with a one second resolution, your updates are likely being ignored and the out-of-date pyc is invoked rather than your updated source.

  • Try removing the pyc file between each import or reload.

  • Alternatively, you can the set the environment variable PYTHONDONTWRITEBYTECODE=1.

  • You can also bypass the import logic by using execfile.


Post a Comment for "Python Reload Module Does Not Take Effect Immediately"