summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/_io/bufferedio.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 3dec67b..dd4e53f 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);