hypercorn icon indicating copy to clipboard operation
hypercorn copied to clipboard

hypercorn autoreload return exit status 0 when reloading encounters Python SyntaxError

Open dodysw3 opened this issue 1 year ago • 0 comments

Problem: exit status 0 is returned when hypercorn with --reload throws an exception like SyntaxError, making the wrapper unable to distinguish if the exit is graceful or not (e.g. systemd auto restart on-failure)

Expectation: exit status non-0 should be returned in this condition.

Reproducing:

app.py:

# pip install hypercorn quart
from quart import Quart

app = Quart(__name__)

@app.route('/')
async def hello():
    return "Hello, World!"

if __name__ == '__main__':
    import hypercorn.asyncio
    from hypercorn.config import Config

    config = Config()
    config.bind = ["127.0.0.1:8000"]

    import asyncio
    asyncio.run(hypercorn.asyncio.serve(app, config))
hypercorn --reload app:app

Then make the syntax error, e.g.:

...
    return "Hello, World!" }
...

The result:

  File "/Users/dody/code/coba/app.py", line 8
    return "Hello, World!"}
                          ^
SyntaxError: unmatched '}'
(venv) $ echo $?
0

This works as expected when hypercorn encounters the syntaxerror before reloading: (continuing from above)

hypercorn --reload app:app
...
  File "/Users/dody/code/coba/app.py", line 8
    return "Hello, World!" }
                           ^
SyntaxError: unmatched '}'
(venv) $ echo $?
1

Thanks for checking!

dodysw3 avatar Dec 13 '24 03:12 dodysw3