Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
IOError: close() called during concurrent operation on the same file object. #2370
Occasionally, I get
@nicoddemus I'm seeing this issue again. If I pass -s, it will create a lot of output and overwhelm my CI logs. This is hard to nail down since I have thousands of tests and its not deterministic. Can some defensive logic be added around the file close statement to avoid this?
I would be OK if we could reproduce the problem and understand what's happening but just adding some defensive logic in there, without knowing why, is problematic in the long term as it might be hiding some bug.
I suggest we investigate more.
I can see from the traceback that the error happens here:
A quick search suggests that threads are somehow involved:
But pytest itself does not use threads internally at all, so I'm puzzled as to how this is happening.
Here's a test file that reproduces it for me 100% of the time:
While this example is silly, the error can come up in practice if there's a background thread logging something at an inopportune moment during shutdown.