[pypy-commit] pypy py3.3: Make sure to grab the import lock when importing. Not sure if this a sufficent fix, but it at least adds this back.
marky1991
pypy.commits at gmail.com
Tue Jan 12 22:23:55 EST 2016
Author: marky1991
Branch: py3.3
Changeset: r81702:b201f36ae568
Date: 2015-12-29 23:41 -0500
http://bitbucket.org/pypy/pypy/changeset/b201f36ae568/
Log: Make sure to grab the import lock when importing. Not sure if this a
sufficent fix, but it at least adds this back.
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
@@ -75,19 +75,25 @@
w_mod = check_sys_modules_w(space, modulename)
if w_mod:
return w_mod
- if modulename in space.builtin_modules:
- return space.getbuiltinmodule(modulename)
+ try:
+ lock = getimportlock(space)
+ lock.acquire_lock()
- ec = space.getexecutioncontext()
- with open(os.path.join(lib_pypy, modulename + '.py')) as fp:
- source = fp.read()
- pathname = "<frozen %s>" % modulename
- code_w = ec.compiler.compile(source, pathname, 'exec', 0)
- w_mod = add_module(space, space.wrap(modulename))
- space.setitem(space.sys.get('modules'), w_mod.w_name, w_mod)
- space.setitem(w_mod.w_dict, space.wrap('__name__'), w_mod.w_name)
- code_w.exec_code(space, w_mod.w_dict, w_mod.w_dict)
- assert check_sys_modules_w(space, modulename)
+ if modulename in space.builtin_modules:
+ return space.getbuiltinmodule(modulename)
+
+ ec = space.getexecutioncontext()
+ with open(os.path.join(lib_pypy, modulename + '.py')) as fp:
+ source = fp.read()
+ pathname = "<frozen %s>" % modulename
+ code_w = ec.compiler.compile(source, pathname, 'exec', 0)
+ w_mod = add_module(space, space.wrap(modulename))
+ space.setitem(space.sys.get('modules'), w_mod.w_name, w_mod)
+ space.setitem(w_mod.w_dict, space.wrap('__name__'), w_mod.w_name)
+ code_w.exec_code(space, w_mod.w_dict, w_mod.w_dict)
+ assert check_sys_modules_w(space, modulename)
+ finally:
+ lock.release_lock(silent_after_fork=True)
return w_mod
@@ -174,6 +180,7 @@
def acquire_lock(self):
# this function runs with the GIL acquired so there is no race
# condition in the creation of the lock
+ print("calling original")
if self.lock is None:
try:
self.lock = self.space.allocate_lock()
@@ -224,7 +231,9 @@
self.lockcounter = 0
def getimportlock(space):
- return space.fromcache(ImportRLock)
+ me = space.fromcache(ImportRLock)
+ print(id(me), "id of lock")
+ return me
# __________________________________________________________________
#
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
@@ -92,18 +92,31 @@
importlock = getimportlock(space)
original_acquire = importlock.acquire_lock
def acquire_lock():
+ print("calling monkeyed")
importlock.count += 1
original_acquire()
importlock.count = 0
+ print(id(acquire_lock), "acq id")
+ monkeypatch.setattr(importlock.__class__, 'acquire_lock', acquire_lock)
+ print(id(getattr(importlock.__class__,
+ "acquire_lock")),
+ "getattr id")
monkeypatch.setattr(importlock, 'acquire_lock', acquire_lock)
+ print(id(getattr(importlock.__class__,
+ "acquire_lock")),
+ "getattr id")
+ print(id(importlock.__class__.acquire_lock), id(importlock.acquire_lock), id(acquire_lock), "alll")
+
# An already imported module
importhook(space, 'sys')
assert importlock.count == 0
# A new module
- importhook(space, '__future__')
+ x = "time"
+ importhook(space, x)
assert importlock.count == 1
+ print("yay")
# Import it again
previous_count = importlock.count
- importhook(space, '__future__')
+ importhook(space, x)
assert importlock.count == previous_count
More information about the pypy-commit
mailing list