1

I am getting multiple emissons of ResourceWarnings when using third party python modules say numpy or tornado. Without editing source code from third party modules, how can we effectively prevent ResourceWarnings from being displayed on terminal, as they are a lot.

I have tried solutions offered from this thread How to disable python warnings to no avail

The ResourceWarning being emmitted is as follows

/usr/local/lib/python3.5/dist-packages/tornado/gen.py:1154: ResourceWarning: unclosed <socket.socket fd=120, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 0)>
self.future, inner)

PS: These are not my warnings from my code, its from third party modules, making it harder to suppress them in python3.5.

CKE
  • 1,533
  • 19
  • 18
  • 29
Therenca
  • 116
  • 6

1 Answers1

0

Is this in a unit test or other environments? The unittest module enables all warnings and overrides other settings. You can either disable the warnings inside your test, or figure out where the unclosed socket is coming from and ensure it gets closed correctly.

I'd recommend taking these warnings seriously, since if you're seeing this you might be holding on to sockets longer than necessary and might see errors in production due to running out of file descriptors.

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50
  • Ben Darnell, this is not from unittests, the warnings are shown to come from within the tornado module itself. I should also say these warnings have just recently emerged as the codebase has been running just fine without any sort of ResourceWarning output. Upon running the codebase on another server, they were emitted. Prior to server migration, there was no such warning. Unless you recommend I dig into third party modules and close the sockets myself, which is not a good idea.... – Therenca Jul 04 '18 at 13:12