diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 3dec67b5c6b..dd4e53f0f2d 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -260,9 +260,11 @@ typedef struct { #ifdef WITH_THREAD #define ENTER_BUFFERED(self) \ - Py_BEGIN_ALLOW_THREADS \ - PyThread_acquire_lock(self->lock, 1); \ - Py_END_ALLOW_THREADS + if (!PyThread_acquire_lock(self->lock, 0)) { \ + Py_BEGIN_ALLOW_THREADS \ + PyThread_acquire_lock(self->lock, 1); \ + Py_END_ALLOW_THREADS \ + } #define LEAVE_BUFFERED(self) \ PyThread_release_lock(self->lock);