Beispiel #1
0
def __import__(*args, **kwargs):
    """
    __import__(name, globals=None, locals=None, fromlist=(), level=0) -> object

    Normally python protects imports against concurrency by doing some locking
    at the C level (at least, it does that in CPython).  This function just
    wraps the normal __import__ functionality in a recursive lock, ensuring that
    we're protected against greenlet import concurrency as well.
    """
    if args and not issubclass(type(args[0]), _allowed_module_name_types):
        # if a builtin has been acquired as a bound instance method,
        # python knows not to pass 'self' when the method is called.
        # No such protection exists for monkey-patched builtins,
        # however, so this is necessary.
        args = args[1:]

    if not __lock_imports:
        return _import(*args, **kwargs)

    module_lock = __module_lock(args[0])  # Get a lock for the module name
    imp_acquire_lock()
    try:
        module_lock.acquire()
        try:
            result = _import(*args, **kwargs)
        finally:
            module_lock.release()
    finally:
        imp_release_lock()
    return result
Beispiel #2
0
def __import__(*args, **kwargs):
    """
    __import__(name, globals=None, locals=None, fromlist=(), level=0) -> object

    Normally python protects imports against concurrency by doing some locking
    at the C level (at least, it does that in CPython).  This function just
    wraps the normal __import__ functionality in a recursive lock, ensuring that
    we're protected against greenlet import concurrency as well.
    """
    if args and not issubclass(type(args[0]), _allowed_module_name_types):
        # if a builtin has been acquired as a bound instance method,
        # python knows not to pass 'self' when the method is called.
        # No such protection exists for monkey-patched builtins,
        # however, so this is necessary.
        args = args[1:]

    if not __lock_imports:
        return _import(*args, **kwargs)

    module_lock = __module_lock(args[0]) # Get a lock for the module name
    imp_acquire_lock()
    try:
        module_lock.acquire()
        try:
            result = _import(*args, **kwargs)
        finally:
            module_lock.release()
    finally:
        imp_release_lock()
    return result
Beispiel #3
0
 def __enter__(self):
     imp_acquire_lock()
     self._save()
     return self
Beispiel #4
0
 def __enter__(self):
     imp_acquire_lock()
     self._save()
     self._replace()
Beispiel #5
0
 def __enter__(self):
     imp_acquire_lock()
     self._save()
     self._replace()