py313: Suppress cheroot warnings

https://github.com/cherrypy/cheroot/issues/734
See #8205
This commit is contained in:
Florian Bruhin 2024-12-09 16:08:47 +01:00
parent 48d3c7d97c
commit 4c7325f912
2 changed files with 22 additions and 0 deletions

View File

@ -12,6 +12,7 @@ parameters or headers with the same name properly.
"""
import sys
import errno
import json
import time
import threading
@ -338,7 +339,26 @@ class WSGIServer(cheroot.wsgi.Server):
self._ready = value
def unraisable_hook(unraisable: "sys.UnraisableHookArgs") -> None:
if (
sys.version_info[:2] == (3, 13)
and isinstance(unraisable.exc_value, OSError)
and unraisable.exc_value.errno == errno.EBADF
and unraisable.object.__qualname__ == "IOBase.__del__"
):
# WORKAROUND for bogus exceptions with cheroot:
# https://github.com/cherrypy/cheroot/issues/734
return
sys.__unraisablehook__(unraisable)
def init_unraisable_hook() -> None:
sys.unraisablehook = unraisable_hook
def main():
init_unraisable_hook()
app.template_folder = END2END_DIR / 'templates'
assert app.template_folder.is_dir(), app.template_folder

View File

@ -47,6 +47,8 @@ def log_request(response):
def main():
webserver_sub.init_unraisable_hook()
port = int(sys.argv[1])
server = webserver_sub.WSGIServer(('127.0.0.1', port), app)