ashleysommer / sanic-synchro-ctx

Plugin to provide an App context that is shared across multiple workers
MIT License
4 stars 0 forks source link

sanic-synchro-ctx incompatible with newer versions of Sanic #2

Open aeburriel opened 1 year ago

aeburriel commented 1 year ago

sanic-synchro-ctx is broken with newer versions of Sanic.

Breaking changes seem to be in Sanic 22.12.0 for the simple example and in Sanic_ext 22.6.0 for the extension example.

sanic_ext_example

sanic_ext_example.py works up to Sanic 22.3.2, fails with Sanic & sanic_ext 22.6.0:

$ sanic sanic_ext_example:app

Traceback (most recent call last):
  File "/home/user/.local/bin/sanic", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.9/site-packages/sanic/__main__.py", line 12, in main
    cli.run()
  File "/home/user/.local/lib/python3.9/site-packages/sanic/cli/app.py", line 85, in run
    app = self._get_app()
  File "/home/user/.local/lib/python3.9/site-packages/sanic/cli/app.py", line 142, in _get_app
    module = import_module(module_name)
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/tmp/sanic-synchro-ctx/examples/sanic_ext_example.py", line 8, in <module>
    Extend(app, extensions=[SanicSynchroCtx])
  File "/home/user/.local/lib/python3.9/site-packages/sanic_ext/bootstrap.py", line 101, in __init__
    extension = Extension.create(ext, app, self.config)
  File "/home/user/.local/lib/python3.9/site-packages/sanic_ext/extensions/base.py", line 69, in create
    extension if isinstance(extension, Extension) else extension()
TypeError: __init__() missing 1 required positional argument: 'app'

simple_example

simple_example.py works up to Sanic 22.9.1, fails with Sanic 22.12.0:

$ sanic simple_example.py:app

Sanic app name 'simple' not found.
App instantiation must occur outside if __name__ == '__main__' block or by using an AppLoader.
See https://sanic.dev/en/guide/deployment/app-loader.html for more details.
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.9/site-packages/sanic/app.py", line 1491, in get_app
    return cls._app_registry[name]
KeyError: 'simple'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.local/lib/python3.9/site-packages/sanic/worker/serve.py", line 55, in worker_serve
    app = app_loader.load()
  File "/home/user/.local/lib/python3.9/site-packages/sanic/worker/loader.py", line 52, in load
    return self.factory()
  File "/home/user/.local/lib/python3.9/site-packages/sanic/app.py", line 1497, in get_app
    raise SanicException(
sanic.exceptions.SanicException: Sanic app name 'simple' not found.
App instantiation must occur outside if __name__ == '__main__' block or by using an AppLoader.
See https://sanic.dev/en/guide/deployment/app-loader.html for more details.
[2023-04-02 15:04:45 +0200] [1949003] [ERROR] Not all workers acknowledged a successful startup. Shutting down.

One of your worker processes terminated before startup was completed. Please solve any errors experienced during startup. If you do not see an exception traceback in your error logs, try running Sanic in in a single process using --single-process or single_process=True. Once you are confident that the server is able to start without errors you can switch back to multiprocess mode.
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-0-0 [1949023]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-1-0 [1949024]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-2-0 [1949025]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-3-0 [1949026]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-4-0 [1949027]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-5-0 [1949028]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-6-0 [1949029]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Killing Sanic-Server-7-0 [1949030]
[2023-04-02 15:04:45 +0200] [1949003] [INFO] Server Stopped
ashleysommer commented 1 year ago

Hi @aeburriel Thanks for the report.

I thought I made a version of this plugin that is compatible with Sanic 22.12. I know I was testing it. Looks like it didn't make it to a release. I will see if I can find some time this week to push the changes out to a release.