ResourceWarning: unclosed ssl.SSLSocket
See original GitHub issueFor some reason I’m getting a ResourceWarning about a unclosed socket, even when I’m specifically closing the socket myself. See testcase below:
python3 -munittest discover
import sys
import boto3
import unittest
BUCKET = ''
KEY = ''
def give_it_to_me():
client = boto3.client('s3')
obj = client.get_object(Bucket=BUCKET, Key=KEY)
try:
yield from iter(lambda: obj['Body'].read(1024), b'')
finally:
print('Im closing it!', file=sys.stderr, flush=True)
obj['Body'].close()
class TestSomeShit(unittest.TestCase):
def test_it(self):
res = give_it_to_me()
for chunk in res:
pass
print('Done', file=sys.stderr, flush=True)
Fill in any BUCKET
and KEY
to see the problem. Attaching my output below:
Im closing it!
test.py:22: ResourceWarning: unclosed <ssl.SSLSocket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('...', 55498), raddr=('...', 443)>
for chunk in res:
Done
.
----------------------------------------------------------------------
Ran 1 test in 0.696s
OK
Issue Analytics
- State:
- Created 8 years ago
- Reactions:82
- Comments:52 (9 by maintainers)
Top Results From Across the Web
ResourceWarning unclosed socket in Python 3 Unit Test
I'm modifying some code to be compatible between Python 2 and Python 3 , but have observed a warning in unit test output....
Read more >sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=4 ...
Description of problem: See Resource warning on various openstack commands: A couple seen on: - openstack overcloud node introspect --all-manageable ...
Read more >Issue 43885: ResourceWarning: unclosed <ssl.SSLSocket ...
... /home/heimes/dev/python/cpython/Lib/test/support/threading_helper.py:209: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AF_INET, ...
Read more >ResourceWarning unclosed socket in Python 3 Unit Test
Python – ResourceWarning unclosed socket in Python 3 Unit Test. pythonpython-3.xpython-unittestsockets. I'm modifying some code to be compatible between ...
Read more >Still observing close file warnings with overcloud commands
ret_value = super(OpenStackShell, self).run_subcommand(argv) sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=4, family=AddressFamily.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@student-t
Don’t use this kind of language, especially not on an open source project where the developers owe you nothing and you are getting their work for free.
If this issue is so important to you that you can’t wait for a fix to be submitted and merged in, then fork the project and fix it yourself, and spare us all this kind of low quality whining.
So no fix? Warning is still important. boto3 developers are lazy.