Could you check, if you might be running out of memory?
Sometimes these library issues are raised even though you are in fact running out of memory.
If that’s the case, I would recommend to reduce the batch size.