Sanic server app fails with an error

My sanic app starts but fails after two seconds with this error.

2022-11-02 23:49:20.281 | INFO     | __main__:<module>:103 - The Env is testnet
[2022-11-02 23:49:20 +0530] [24882] [INFO]
  ┌─────────────────────────────────────────────────────────────────────────────────────────────────────┐
  │                                            Sanic v22.9.1                                            │
  │                                   Goin' Fast @ http://0.0.0.0:8001                                  │
  ├───────────────────────┬─────────────────────────────────────────────────────────────────────────────┤
  │                       │        mode: production, single worker                                      │
  │     ▄███ █████ ██     │      server: sanic, HTTP/1.1                                                │
  │    ██                 │      python: 3.9.15                                                         │
  │     ▀███████ ███▄     │    platform: macOS-12.0-arm64-arm-64bit                                     │
  │                 ██    │ auto-reload: enabled, /Users/saurav/Programs/pingbox/tx_relayers/src/config │
  │    ████ ████████▀     │    packages: sanic-routing==22.8.0                                          │
  │                       │                                                                             │
  │ Build Fast. Run Fast. │                                                                             │
  └───────────────────────┴─────────────────────────────────────────────────────────────────────────────┘

[2022-11-02 23:49:20 +0530] [24882] [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application.
Process Sanic-Server-0-0:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/opt/homebrew/Cellar/[email protected]/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/worker/serve.py", line 106, in worker_serve
    return _serve_http_1(
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/server/runners.py", line 230, in _serve_http_1
    loop.run_until_complete(app._startup())
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/app.py", line 1509, in _startup
    self.finalize()
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/app.py", line 1483, in finalize
    raise e
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/app.py", line 1480, in finalize
    self.router.finalize()
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/router.py", line 190, in finalize
    super().finalize(*args, **kwargs)
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic_routing/router.py", line 319, in finalize
    raise FinalizationError("Cannot finalize with no routes defined.")
sanic_routing.exceptions.FinalizationError: Cannot finalize with no routes defined.
/opt/homebrew/Cellar/[email protected]/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py:331: RuntimeWarning: coroutine 'Loop.create_server' was never awaited
  traceback.print_exc()
[2022-11-02 23:49:25 +0530] [24882] [ERROR] Not all workers are ack. Shutting down.
[2022-11-02 23:49:25 +0530] [24882] [ERROR] Experienced exception while trying to serve
Traceback (most recent call last):
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/mixins/startup.py", line 851, in serve
    manager.run()
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/worker/manager.py", line 63, in run
    self.monitor()
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/worker/manager.py", line 99, in monitor
    self.wait_for_ack()
  File "/Users/saurav/Programs/pingbox/tx_relayers/lib/python3.9/site-packages/sanic/worker/manager.py", line 139, in wait_for_ack
    sys.exit(1)
SystemExit: 1
[2022-11-02 23:49:25 +0530] [24882] [INFO] Server Stopped

:point_up_2:See above. You do not have any routes attached to your app instance.

I do face the same issue.
@ahopkins Can you correct me where I am wrong.

In server.py, I define instanstiate the app and in another module ( in the same directory ), I try to retrieve as below. Thats where my handlers are defined.
image

Where do you import the module? If you are doing Sanic.get_app in the global scope, the import needs to be after app=Sanic(...).

1 Like

Thanks @ahopkins . I think i made some mistake in the order of import.