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

Update agent.py to prevent ResourceWarning #459

Closed
wants to merge 1 commit into from
Closed

Update agent.py to prevent ResourceWarning #459

wants to merge 1 commit into from

Conversation

@tkrapp
Copy link

@tkrapp tkrapp commented Dec 16, 2014

When using Python 3 with warnings "enabled" you get a ResourceWarning each time the '_close'-method of AgentSSH is called.
Closing the socket stored in '_conn' explicitly before setting the attribute to None prevents this error.

When using Python 3 with warnings "enabled" you get a ResourceWarning each time the '_close'-method of AgentSSH is called.
Closing the socket stored in '_conn' explicitly before setting the attribute to None prevents this error.
@bitprophet
Copy link
Member

@bitprophet bitprophet commented Dec 17, 2014

Wish the git history was clearer, looks like that commented-out line was added with the original agent support itself - so it's unclear why the original author apparently had the idea to do this, then decided not to at the end.

My guess, looking at the module, is it was a (crappy) defense against closing prior to actual connectivity (i.e. creating the agent, then calling close without connect, would explode as None has no close method). Though as-used, this never happens as connect is called on __init__ in the main public Agent class.

Feels like we could amend your PR to say if self._conn is not None: and that should cover things. I'll test this out now.

@bitprophet
Copy link
Member

@bitprophet bitprophet commented Dec 17, 2014

Also noticed we sometimes explicitly call ._conn.close from the related classes (boo!) but it looks like multiple calls to .close don't cause a stink, so meh.

bitprophet added a commit that referenced this pull request Dec 17, 2014
@tkrapp tkrapp deleted the tkrapp:patch-1 branch Dec 18, 2014
dkhapun pushed a commit to cyberx-labs/paramiko that referenced this pull request Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants