sanic: Module import fails when auto_reload is active

I have two piece of code (the structure has been simplified for clarity sake) First in base.py

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# module: init0

from abc   import ABCMeta
from sanic import Sanic

class BaseService( metaclass = ABCMeta ):
    def create_app( self ) -> Sanic:
        app = Sanic( __name__ )
        return app

# app = BaseService().create_app()

# app.run( host  = '0.0.0.0',
#      port  = 5000,
#      debug = True,
#     )

print('[DONE]')

Second in run_test.py

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# module: init0

from init0.base import BaseService

def main():
    app = BaseService().create_app()
    app.run( host  = '0.0.0.0',
         port  = 5000,
         debug = True,
        )
    return

if __name__ == '__main__':
    main()

If I were to run python -m init0.run_test with debug = False then everything works perfectly, however if it’s debug = True, then it’d throw me ModuleNotFoundError: No module named 'init0'

Is it some sort of loading error somewhere that I need to configure beforehand?

Thanks a lot in advance

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

ok, i think it’s sth. wrong with the auto_reload logic…

You can set (workers > 1 or debug=false) for verifying, since the auto_reload will be disabled in such cases.