Skip to content

Commit

Permalink
Support uvloop >= 0.18 and the loop_factory argument
Browse files Browse the repository at this point in the history
This brings Hypercorn in line with what is required for Python 3.13
onwards.
  • Loading branch information
pgjones committed May 28, 2024
1 parent bc6e1c0 commit edd0aac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ taskgroup = { version = "*", python = "<3.11", allow-prereleases = true }
tomli = { version = "*", python = "<3.11" }
trio = { version = ">=0.22.0", optional = true }
typing_extensions = { version = "*", python = "<3.11" }
uvloop = { version = "*", markers = "platform_system != 'Windows'", optional = true }
uvloop = { version = ">=0.18", markers = "platform_system != 'Windows'", optional = true }
wsproto = ">=0.14.0"

[tool.poetry.dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions src/hypercorn/asyncio/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ def uvloop_worker(
import uvloop
except ImportError as error:
raise Exception("uvloop is not installed") from error
else:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

app = load_application(config.application_path, config.wsgi_max_body_size)

Expand All @@ -220,6 +218,7 @@ def uvloop_worker(
partial(worker_serve, app, config, sockets=sockets),
debug=config.debug,
shutdown_trigger=shutdown_trigger,
loop_factory=uvloop.new_event_loop,
)


Expand All @@ -228,8 +227,9 @@ def _run(
*,
debug: bool = False,
shutdown_trigger: Optional[Callable[..., Awaitable[None]]] = None,
loop_factory: Callable[[], asyncio.AbstractEventLoop] | None = None,
) -> None:
with Runner(debug=debug) as runner:
with Runner(debug=debug, loop_factory=loop_factory) as runner:
runner.get_loop().set_exception_handler(_exception_handler)
runner.run(main(shutdown_trigger=shutdown_trigger))

Expand Down

0 comments on commit edd0aac

Please sign in to comment.