In win7 x64 debug mode with thread_debug=1, every PyThread_release_lock() is accompanied with a message on stderr: Could not PyThread_release_lock() error: 0
In all PyMUTEX_* and most PyCOND_* functions, all the underlying APIs are void. So there's no point for the functions to return anything other than as convention. A comment at the start of condvar.h says: "APIs generally return 0 on success and non-zero on error". In Python\ceval_gil.h:57, there are boilerplace checker macros for them (which will never fire). So I guess this is done for uniformity. Regardless, PyMUTEX_UNLOCK and PyMUTEX_LOCK at least are called both with and without checking the return value. So I would drop the pretense and make these fns void. --- That said, the reported error still persists after the fix. The code confusing about which value LeaveNonRecursiveMutex should return on success. Pushed another commit, confirmed to work now.
> So I would drop the pretense and make these fns void. Scratch that. In POSIX, they are #define'd as pthread fns which do return an error code. So, nothing more to do here.