Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    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
Beispiel #4
0
def reinit_lock(space):
    if space.config.objspace.usemodules.thread:
        importing.getimportlock(space).reinit_lock()
Beispiel #5
0
def release_lock(space):
    if space.config.objspace.usemodules.thread:
        importing.getimportlock(space).release_lock(silent_after_fork=False)
Beispiel #6
0
def acquire_lock(space):
    if space.config.objspace.usemodules.thread:
        importing.getimportlock(space).acquire_lock()
Beispiel #7
0
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
Beispiel #8
0
def reinit_lock(space):
    if space.config.objspace.usemodules.thread:
        importing.getimportlock(space).reinit_lock()
Beispiel #9
0
def release_lock(space):
    if space.config.objspace.usemodules.thread:
        importing.getimportlock(space).release_lock(silent_after_fork=False)
Beispiel #10
0
def acquire_lock(space):
    if space.config.objspace.usemodules.thread:
        importing.getimportlock(space).acquire_lock()
Beispiel #11
0
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
Beispiel #12
0
def lock_held(space):
    if space.config.objspace.usemodules.thread:
        return space.wrap(importing.getimportlock(space).lock_held())
    else:
        return space.w_False