Skip to content

Commit

Permalink
Move asyncio.get_event_loop() into coroutine (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Jul 26, 2024
1 parent 0a1dd69 commit 103d781
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kr8s/_portforward.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
)
self._resource = resource
self.pod = None
self._loop = asyncio.get_event_loop()
self._loop: asyncio.AbstractEventLoop | None = None
self._tasks: list[asyncio.Task] = []
self._run_task = None
self._bg_future: asyncio.Future | None = None
Expand All @@ -118,6 +118,8 @@ async def __aexit__(self, *args, **kwargs):

async def start(self) -> int:
"""Start a background task with the port forward running."""
if self._loop is None:
self._loop = asyncio.get_event_loop()
if self._bg_task is not None:
return self.local_port

Expand Down

0 comments on commit 103d781

Please sign in to comment.