Skip to content

Commit

Permalink
handle unclosed socket resource warning
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Aug 8, 2022
1 parent bebf46d commit b484e54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -19,6 +19,8 @@ Unreleased
- ``LocalProxy.__wrapped__`` is always set to the wrapped object when
the proxy is unbound, fixing an issue in doctest that would cause it
to fail. :issue:`2485`
- Address one ``ResourceWarning`` related to the socket used by
``run_simple``. :issue:`2421`


Version 2.2.1
Expand Down
3 changes: 3 additions & 0 deletions src/werkzeug/serving.py
Expand Up @@ -1061,6 +1061,9 @@ def run_simple(
if not is_running_from_reloader():
s = prepare_socket(hostname, port)
fd = s.fileno()
# Silence a ResourceWarning about an unclosed socket. This object is no longer
# used, the server will create another with fromfd.
s.detach()
os.environ["WERKZEUG_SERVER_FD"] = str(fd)
else:
fd = int(os.environ["WERKZEUG_SERVER_FD"])
Expand Down

0 comments on commit b484e54

Please sign in to comment.