import imp
SYS_PREFIX = '/usr/lib'
for k, v in list(sys.modules.items()):
    if not hasattr(v, '__file__'):
        continue
if v.__file__.startswith(SYS_PREFIX):
    continue
if k == '__main__':
    continue
print('reloading %s [%s]' % (k, v.__file__))
imp.reload(v)
How to make pdb recognize that the source has changed between runs?