Skip to content

Commit edd0aac

Browse files
committed
Support uvloop >= 0.18 and the loop_factory argument
This brings Hypercorn in line with what is required for Python 3.13 onwards.
1 parent bc6e1c0 commit edd0aac

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ taskgroup = { version = "*", python = "<3.11", allow-prereleases = true }
3838
tomli = { version = "*", python = "<3.11" }
3939
trio = { version = ">=0.22.0", optional = true }
4040
typing_extensions = { version = "*", python = "<3.11" }
41-
uvloop = { version = "*", markers = "platform_system != 'Windows'", optional = true }
41+
uvloop = { version = ">=0.18", markers = "platform_system != 'Windows'", optional = true }
4242
wsproto = ">=0.14.0"
4343

4444
[tool.poetry.dev-dependencies]

src/hypercorn/asyncio/run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ def uvloop_worker(
207207
import uvloop
208208
except ImportError as error:
209209
raise Exception("uvloop is not installed") from error
210-
else:
211-
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
212210

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

@@ -220,6 +218,7 @@ def uvloop_worker(
220218
partial(worker_serve, app, config, sockets=sockets),
221219
debug=config.debug,
222220
shutdown_trigger=shutdown_trigger,
221+
loop_factory=uvloop.new_event_loop,
223222
)
224223

225224

@@ -228,8 +227,9 @@ def _run(
228227
*,
229228
debug: bool = False,
230229
shutdown_trigger: Optional[Callable[..., Awaitable[None]]] = None,
230+
loop_factory: Callable[[], asyncio.AbstractEventLoop] | None = None,
231231
) -> None:
232-
with Runner(debug=debug) as runner:
232+
with Runner(debug=debug, loop_factory=loop_factory) as runner:
233233
runner.get_loop().set_exception_handler(_exception_handler)
234234
runner.run(main(shutdown_trigger=shutdown_trigger))
235235

0 commit comments

Comments
 (0)