Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/faq/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ Here's how to adapt the example just above:

The server will exit after all clients disconnect.

With the :mod:`threading` implementation, call ``Server.shutdown`` with
``close_connections=False`` instead::

from websockets.sync.server import serve
import threading

server = serve(handler, "localhost", 8765)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.start()
try:
# Run the application until it's time to stop.
...
finally:
server.shutdown(close_connections=False)
server_thread.join()

The server will return from ``Server.shutdown`` after all clients
disconnect.

How do I implement a health check?
----------------------------------

Expand Down
3 changes: 3 additions & 0 deletions docs/project/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Improvements

* :func:`~asyncio.client.connect` now closes connections with close code 1011
(internal error) when exiting the context manager with an exception.
* The FAQ documents how to stop asyncio and threading servers while keeping
existing connections open. See `issue #1756
<https://github.com/python-websockets/websockets/issues/1756>`_.

.. _17.1:

Expand Down