Skip to content

Commit

Permalink
Add FAQ on stopping a server.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Feb 20, 2022
1 parent 330dd3d commit a113adc
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions docs/howto/faq.rst
Expand Up @@ -220,11 +220,22 @@ To listen only on IPv4, specify ``host="0.0.0.0"`` or ``family=socket.AF_INET``.

Refer to the documentation of :meth:`~asyncio.loop.create_server` for details.

How do I close a connection properly?
.....................................
How do I close a connection?
............................

websockets takes care of closing the connection when the handler exits.

How do I stop a server?
.......................

Exit the :func:`~server.serve` context manager.

Here's an example that terminates cleanly when it receives SIGTERM on Unix:

.. literalinclude:: ../../example/shutdown_server.py
:emphasize-lines: 12-15,18


How do I run a HTTP server and WebSocket server on the same port?
.................................................................

Expand Down Expand Up @@ -265,8 +276,8 @@ change it to::
async with connect(...) as websocket:
await do_some_work()

How do I close a connection properly?
.....................................
How do I close a connection?
............................

The easiest is to use :func:`~client.connect` as a context manager::

Expand All @@ -287,8 +298,8 @@ Use :func:`connect` as an asynchronous iterator::
Make sure you handle exceptions in the ``async for`` loop. Uncaught exceptions
will break out of the loop.

How do I stop a client that is continuously processing messages?
................................................................
How do I stop a client that is processing messages in a loop?
.............................................................

You can close the connection.

Expand Down

0 comments on commit a113adc

Please sign in to comment.