I have a multithreaded program with a line that causes a warning I want to silence. I don't want to silence warnings anywhere else in the code.
I could do this, as suggested in the docs:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
line_that_causes_warning()
But the docs also say that it's not thread-safe, because it sets the module-level warning filter.
I realize I could probably solve that with something crazy like protecting this section with a lock, but is there a nice way to make this thread-safe?