Skip to content

Commit

Permalink
Merge pull request #2498 from pallets/socket-warning
Browse files Browse the repository at this point in the history
handle unclosed socket resource warning
  • Loading branch information
davidism authored Aug 8, 2022
2 parents bebf46d + b484e54 commit 110b4cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 110b4cd

Please sign in to comment.