()
Enables (activates) the Splitbrain machinery; must be called before entering 
    ``splitbrain`` or ``localbrain`` contexts
Enables (activates) the Splitbrain machinery; must be called before entering 
    ``splitbrain`` or ``localbrain`` contexts
Enables ( activates ) the Splitbrain machinery ; must be called before entering splitbrain or localbrain contexts
def enable_splitbrain():
    """Enables (activates) the Splitbrain machinery; must be called before entering 
    ``splitbrain`` or ``localbrain`` contexts"""
    global _enabled
    if _enabled:
        return
    sys.modules["sys"] = rsys
    for modname in routed_modules:
        try:
            realmod = _orig_import(modname, [], [], "*")
        except ImportError:
            continue
        rmod = RoutedModule(realmod)
        sys.modules[modname] = rmod
        for ref in gc.get_referrers(realmod):
            if not isinstance(ref, dict) or "__name__" not in ref or ref.get("__file__") is None:
                continue
            n = ref["__name__"]
            if n in routed_modules or n.startswith("rpyc") or n.startswith("importlib") or n.startswith("imp"):
                continue
            for k, v in ref.items():
                if v is realmod:
                    #print ("## %s.%s = %s" % (ref["__name__"], ref[k], modname))
                    ref[k] = rmod

    builtins.__import__ = _importer
    for funcname in ["open", "execfile", "file"]:
        if not hasattr(builtins, funcname):
            continue
        def mkfunc(funcname, origfunc):
            @functools.wraps(getattr(builtins, funcname))
            def tlbuiltin(*args, **kwargs):
                if hasattr(router, "conn"):
                    func = getattr(router.conn.builtins, funcname)
                else:
                    func = origfunc
                return func(*args, **kwargs)
            return tlbuiltin
        origfunc = getattr(builtins, funcname)
        _prev_builtins[funcname] = origfunc
        setattr(builtins, funcname, mkfunc(funcname, origfunc))
    
    _enabled = True
def enable_splitbrain ( ) : global _enabled if _enabled : return sys . modules [ "sys" ] = rsys for modname in routed_modules : try : realmod = _orig_import ( modname , [ ] , [ ] , "*" ) except ImportError : continue rmod = RoutedModule ( realmod ) sys . modules [ modname ] = rmod for ref in gc . get_referrers ( realmod ) : if not isinstance ( ref , dict ) or "__name__" not in ref or ref . get ( "__file__" ) is None : continue n = ref [ "__name__" ] if n in routed_modules or n . startswith ( "rpyc" ) or n . startswith ( "importlib" ) or n . startswith ( "imp" ) : continue for k , v in ref . items ( ) : if v is realmod : #print ("## %s.%s = %s" % (ref["__name__"], ref[k], modname)) ref [ k ] = rmod builtins . __import__ = _importer for funcname in [ "open" , "execfile" , "file" ] : if not hasattr ( builtins , funcname ) : continue def mkfunc ( funcname , origfunc ) : @ functools . wraps ( getattr ( builtins , funcname ) ) def tlbuiltin ( * args , * * kwargs ) : if hasattr ( router , "conn" ) : func = getattr ( router . conn . builtins , funcname ) else : func = origfunc return func ( * args , * * kwargs ) return tlbuiltin origfunc = getattr ( builtins , funcname ) _prev_builtins [ funcname ] = origfunc setattr ( builtins , funcname , mkfunc ( funcname , origfunc ) ) _enabled = True