diff --git a/.github/workflows/nox.yml b/.github/workflows/nox.yml index a03b2d7b..69dc0051 100644 --- a/.github/workflows/nox.yml +++ b/.github/workflows/nox.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: platform: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.11", "3.12", "3.13"] + python-version: ["3.11", "3.12", "3.13", "3.14"] steps: - uses: actions/checkout@v4 diff --git a/adaptive/runner.py b/adaptive/runner.py index b2e5ec9a..1ab058a1 100644 --- a/adaptive/runner.py +++ b/adaptive/runner.py @@ -626,7 +626,7 @@ def __init__( raise_if_retries_exceeded=raise_if_retries_exceeded, allow_running_forever=True, ) - self.ioloop = ioloop or asyncio.get_event_loop() + self.ioloop = ioloop if ioloop is not None else _get_or_create_event_loop() # When the learned function is 'async def', we run it # directly on the event loop, and not in the executor. @@ -987,7 +987,22 @@ def replay_log( getattr(learner, method)(*args) -# -- Internal executor-related, things +# -- Internal executor-related things + + +def _get_or_create_event_loop() -> asyncio.AbstractEventLoop: + """Get the running event loop or create a new one. + + In Python 3.10+, asyncio.get_event_loop() is deprecated when no loop is running. + In Python 3.14+, it raises RuntimeError instead of creating a new loop. + This function provides a compatible way to get or create an event loop. + """ + try: + return asyncio.get_running_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + return loop def _ensure_executor(executor: ExecutorTypes | None) -> concurrent.Executor: diff --git a/noxfile.py b/noxfile.py index 71a2217a..06b816fc 100644 --- a/noxfile.py +++ b/noxfile.py @@ -6,7 +6,7 @@ nox.options.default_venv_backend = "uv" -python = ["3.11", "3.12", "3.13"] +python = ["3.11", "3.12", "3.13", "3.14"] num_cpus = os.cpu_count() or 1 xdist = ("-n", "auto") if num_cpus > 2 else () diff --git a/pyproject.toml b/pyproject.toml index 5c7186e9..e3f4d28f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", ] dependencies = [ "scipy",