def test_lock(self, space, monkeypatch): from pypy.module.imp.importing import getimportlock, importhook # Force importing the module _file now space.builtin.get('file') # Monkeypatch the import lock and add a counter importlock = getimportlock(space) original_acquire = importlock.acquire_lock def acquire_lock(): importlock.count += 1 original_acquire() importlock.count = 0 monkeypatch.setattr(importlock, 'acquire_lock', acquire_lock) # An already imported module importhook(space, 'sys') assert importlock.count == 0 # A new module importhook(space, 're') assert importlock.count == 9 # Import it again previous_count = importlock.count importhook(space, 're') assert importlock.count == previous_count
def test_lock(self, space, monkeypatch): from pypy.module.imp.importing import getimportlock, importhook # Force importing the module _file now space.builtin.get('file') # Monkeypatch the import lock and add a counter importlock = getimportlock(space) original_acquire = importlock.acquire_lock def acquire_lock(): importlock.count += 1 original_acquire() importlock.count = 0 monkeypatch.setattr(importlock, 'acquire_lock', acquire_lock) # An already imported module importhook(space, 'sys') assert importlock.count == 0 # A new module importhook(space, 're') assert importlock.count == 7 # Import it again previous_count = importlock.count importhook(space, 're') assert importlock.count == previous_count
def test_lock(self, space, monkeypatch): from pypy.module.imp.importing import getimportlock, importhook # Monkeypatch the import lock and add a counter importlock = getimportlock(space) original_acquire = importlock.acquire_lock def acquire_lock(): importlock.count += 1 original_acquire() importlock.count = 0 monkeypatch.setattr(importlock, 'acquire_lock', acquire_lock) # An already imported module importhook(space, 'sys') assert importlock.count == 0 # A new module importhook(space, '__future__') assert importlock.count == 1 # Import it again previous_count = importlock.count importhook(space, '__future__') assert importlock.count == previous_count
def reinit_lock(space): if space.config.objspace.usemodules.thread: importing.getimportlock(space).reinit_lock()
def release_lock(space): if space.config.objspace.usemodules.thread: importing.getimportlock(space).release_lock(silent_after_fork=False)
def acquire_lock(space): if space.config.objspace.usemodules.thread: importing.getimportlock(space).acquire_lock()
def lock_held(space): if space.config.objspace.usemodules.thread: return space.newbool( importing.getimportlock(space).lock_held_by_anyone()) else: return space.w_False
def lock_held(space): if space.config.objspace.usemodules.thread: return space.wrap(importing.getimportlock(space).lock_held_by_anyone()) else: return space.w_False
def lock_held(space): if space.config.objspace.usemodules.thread: return space.wrap(importing.getimportlock(space).lock_held()) else: return space.w_False