Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor web server shutdown procedure #384

Closed
asvetlov opened this issue May 30, 2015 · 6 comments
Closed

Refactor web server shutdown procedure #384

asvetlov opened this issue May 30, 2015 · 6 comments
Labels

Comments

@asvetlov
Copy link
Member

Now we should use complicated code for graceful shutdown:

loop = asyncio.get_event_loop()
handler = app.make_handler()
f = loop.create_server(handler, '0.0.0.0', 8080)
srv = loop.run_until_complete(f)
print('serving on', srv.sockets[0].getsockname())
try:
    loop.run_forever()
except KeyboardInterrupt:
    pass
finally:
    loop.run_until_complete(handler.finish_connections(1.0))
    srv.close()
    loop.run_until_complete(srv.wait_closed())
    loop.run_until_complete(app.finish())
loop.close()

The problem is:

  1. finally block is very complex
  2. It doesn't prevent establishing new connections by client on handler.finish_connections() call.

I guess add new API like:

finalizer = yield from app.create_server(...)
try:
    loop.run_forever()
finally:
    yield from finalizer 
@ludovic-gasc
Copy link
Contributor

+2

@asvetlov
Copy link
Member Author

Well, finalizer api should be more complex:

finalizer.close(3.0)
yield from finalizer.wait_closed()

@asvetlov
Copy link
Member Author

Or even

app.close(3.0)
yield from app.wait_closed()

to mimic asyncio server protocol and to avoid inventing new Finalizer class.

@fafhrd91
Copy link
Member

-10, "establishing new connections" is not a concern of application. you want to copy whole create_server api from asyncio?

@asvetlov
Copy link
Member Author

Fixed by #734

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants