pytogo / portforward

Kubernetes Port-Forward Go-Edition For Python
https://portforward.readthedocs.io
MIT License
17 stars 6 forks source link

Use without context manager gives error #36

Closed nampord closed 8 months ago

nampord commented 8 months ago

Description

port forwarding with a context works well

with portforward.forward(namespace, pod_name,12345, pod_port):

do work ...

  #e.g. working with sqlachemy 
 engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:12345/mydatabase")
 ... 

However

forwarder = portforward.forward(namespace, pod_name, 12345, pod_port) engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:12345/mydatabase") .... forwarder.stop()

does not work ( connection to server at "localhost" (127.0.0.1), port 12345 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections )

According to https://portforward.readthedocs.io/en/latest/portforward.html#module-portforward should work as well

Anything I missed ?

corka149 commented 8 months ago

Hi @nampord.

you are right. And I have no clue why I wrote it like this in the docs. But the code can be easily changed to make it work

Try this instead

forwarder = portforward.PortForwarder(namespace, pod_name, 12345, pod_port)
forwarder.forward()
engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:12345/mydatabase")
...
forwarder.stop()

I will remove this wrong part of the documentation.

corka149 commented 8 months ago

I hope my comment helped you. Else feel free to reopen the issue.

nampord commented 8 months ago

Yes, it works perfectly. Thanks a lot.

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: Sebastian Ziemann @.> Sent: Thursday, February 22, 2024 9:38:16 PM To: pytogo/portforward @.> Cc: Frank Dropmann @.>; Mention @.> Subject: Re: [pytogo/portforward] Use without context manager gives error (Issue #36)

Closed #36https://github.com/pytogo/portforward/issues/36 as completed.

— Reply to this email directly, view it on GitHubhttps://github.com/pytogo/portforward/issues/36#event-11896381235, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABZECA7RORWKAME7TB45NW3YU6UDRAVCNFSM6AAAAABDO6EAHOVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRHA4TMMZYGEZDGNI. You are receiving this because you were mentioned.Message ID: @.***>