[pypy-commit] pypy default: Test and fix (struys and eevee on http://stackoverflow.com/questions/23816549)
arigo
noreply at buildbot.pypy.org
Sat May 24 11:12:12 CEST 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r71693:69ff0c3801ca
Date: 2014-05-24 11:11 +0200
http://bitbucket.org/pypy/pypy/changeset/69ff0c3801ca/
Log: Test and fix (struys and eevee on
http://stackoverflow.com/questions/23816549)
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -748,11 +748,11 @@
self.lockcounter = 0
def lock_held_by_someone_else(self):
- return self.lockowner is not None and not self.lock_held()
+ me = self.space.getexecutioncontext() # used as thread ident
+ return self.lockowner is not None and self.lockowner is not me
- def lock_held(self):
- me = self.space.getexecutioncontext() # used as thread ident
- return self.lockowner is me
+ def lock_held_by_anyone(self):
+ return self.lockowner is not None
def acquire_lock(self):
# this function runs with the GIL acquired so there is no race
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -165,7 +165,7 @@
def lock_held(space):
if space.config.objspace.usemodules.thread:
- return space.wrap(importing.getimportlock(space).lock_held())
+ return space.wrap(importing.getimportlock(space).lock_held_by_anyone())
else:
return space.w_False
diff --git a/pypy/module/thread/test/test_import_lock.py b/pypy/module/thread/test/test_import_lock.py
--- a/pypy/module/thread/test/test_import_lock.py
+++ b/pypy/module/thread/test/test_import_lock.py
@@ -62,6 +62,28 @@
self.waitfor(lambda: done)
assert done
+ def test_lock_held_by_another_thread(self):
+ import thread, imp
+ lock_held = thread.allocate_lock()
+ test_complete = thread.allocate_lock()
+ lock_released = thread.allocate_lock()
+ def other_thread():
+ imp.acquire_lock() # 3
+ assert imp.lock_held()
+ lock_held.release() # 4
+ test_complete.acquire() # 7
+ imp.release_lock() # 8
+ lock_released.release() # 9
+ lock_held.acquire()
+ test_complete.acquire()
+ lock_released.acquire()
+ #
+ thread.start_new_thread(other_thread, ()) # 1
+ lock_held.acquire() # 2
+ assert imp.lock_held() # 5
+ test_complete.release() # 6
+ lock_released.acquire() # 10
+
class TestImportLock:
def test_lock(self, space, monkeypatch):
from pypy.module.imp.importing import getimportlock, importhook
More information about the pypy-commit
mailing list