ResourceWarning: unclosed <socket.socket>
See original GitHub issueHello.
It seems that in certain situations http socket isn’t properly closed.
/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py:395: ResourceWarning: unclosed <socket.socket fd=7, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0, raddr=/Users/stas/Library/Containers/com.docker.docker/Data/s60>
Python 3.5.1 on OSX.
Can be reproduced with following script:
import unittest
import docker
# Warning depends on code layout, so add here some ballast classes,
# probably that puts GC in specific position.
class A(object):
def __init__(self, node):
print('A')
class B(object):
def __init__(self, node):
print('B')
class C(object):
def __init__(self, node):
print('C')
class D(object):
def __init__(self, node):
print('D')
class E(object):
def __init__(self, node):
print('E')
class SingleNodePartition(object):
def __init__(self, node):
self.node = node
self.docker_api = docker.Client()
def container_exec(self, node, command):
exec_id = self.docker_api.exec_create(node, command, user='root')
output = self.docker_api.exec_start(exec_id)
def start(self):
self.container_exec(self.node, "ls")
self.container_exec(self.node, "ls")
self.container_exec(self.node, "ls")
self.container_exec(self.node, "ls")
class RecoveryTest(unittest.TestCase):
def test_node_partition(self):
failure = SingleNodePartition('node3')
failure.start()
if __name__ == '__main__':
unittest.main()
Issue Analytics
- State:
- Created 7 years ago
- Reactions:19
- Comments:6
Top Results From Across the Web
ResourceWarning unclosed socket in Python 3 Unit Test
unittest 's tearDown method allows you to define some code that will be run after each test. Using this hook to close the...
Read more >unclosed socket.socket when I run a unittest? · Issue #3912 ...
This warning happens because Requests uses a keep-alive model that means we try not to explicitly close sockets in many cases. Exactly why...
Read more >ResourceWarning: unclosed <socket.socket [closed] fd=3 ...
_socket.socket object destructor emits a ResourceWarning if the socket is not closed. The problem is this warning: build/Lib/contextlib.py:60: ...
Read more >[PYTHON-2338] _RttMonitor causes ResourceWarning
Noticed this ResourceWarning for an unclosed socket while running the tests. The ResourceWarning seem to randomly occur throughout the test ...
Read more >ResourceWarning unclosed socket in Python 3 Unit Test
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py:601: ResourceWarning: unclosed socket.socket fd=4, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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
Has this been fixed yet? I get this with docker py v4.2.0
as a workaround:
usage: