Skip to content

Commit

Permalink
Sync in asyncio (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Apr 30, 2023
1 parent 6cf29b2 commit 075fdc5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: actions/cache@v2
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}
key: pydeps-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
- run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'
- run: poetry install --no-interaction
Expand Down
4 changes: 4 additions & 0 deletions kr8s/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import inspect
from typing import Any, AsyncGenerator, Callable, Generator, Tuple

import nest_asyncio

nest_asyncio.apply()


def _get_event_loop() -> asyncio.AbstractEventLoop:
try:
Expand Down
1 change: 0 additions & 1 deletion kr8s/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def test_version_sync():
assert "major" in version


@pytest.mark.xfail(reason="Cannot run nested event loops", raises=RuntimeError)
async def test_version_sync_in_async():
kubernetes = kr8s.api()
version = kubernetes.version()
Expand Down
14 changes: 13 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ python = "^3.8"
aiohttp = "^3.8.4"
pyyaml = "^6.0"
asyncio-atexit = "^1.0.1"
nest-asyncio = "^1.5.6"


[tool.poetry.group.test.dependencies]
Expand Down

0 comments on commit 075fdc5

Please sign in to comment.