Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using sync port forward context manager in IPython #285

Open
jacobtomlinson opened this issue Jan 11, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Jan 11, 2024

Which project are you reporting a bug for?

kr8s

What happened?

When I run the following snippet in IPython I get an error.

import kr8s
try:
    pod = kr8s.objects.Pod.gen(name="test-pod", image="nginx:latest", ports=[{"containerPort": 80}])
    pod.create()
    with pod.portforward(80) as port:
        print(port)
finally:
    pod.delete()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[1], line 5
      3     pod = kr8s.objects.Pod.gen(name="test-pod", image="nginx:latest", ports=[{"containerPort": 80}])
      4     pod.create()
----> 5     with pod.portforward(80) as port:
      6         print(port)
      7 finally:

File ~/Projects/kr8s-org/kr8s/kr8s/_objects.py:856, in Pod.portforward(self, remote_port, local_port, address)
    854 if self._asyncio:
    855     return AsyncPortForward(self, remote_port, local_port, address)
--> 856 return SyncPortForward(self, remote_port, local_port, address)

File ~/Projects/kr8s-org/kr8s/kr8s/_portforward.py:104, in PortForward.__init__(self, resource, remote_port, local_port, address)
    102 self._resource = resource
    103 self.pod = None
--> 104 self._loop = asyncio.get_event_loop()
    105 self._tasks = []
    106 self._run_task = None

File ~/miniconda3/envs/kr8s/lib/python3.11/asyncio/events.py:677, in BaseDefaultEventLoopPolicy.get_event_loop(self)
    674     self.set_event_loop(self.new_event_loop())
    676 if self._local._loop is None:
--> 677     raise RuntimeError('There is no current event loop in thread %r.'
    678                        % threading.current_thread().name)
    680 return self._local._loop

RuntimeError: There is no current event loop in thread 'MainThread'.

Anything else?

Running this in the standard Python REPL or in a script doesn't reproduce the issue.

@jacobtomlinson jacobtomlinson added the bug Something isn't working label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant