def _init_local_namespace(ns, init_code=None, force=False):
    if not ns in _g_local_namespaces:
        if opt_allow_new_namespaces or force:
            daemon_log('added local namespace "%s"' % (ns,))
            _g_local_namespaces[ns] = {
                "pythonshare_ns": Pythonshare_ns(ns),
                "Async_rv": pythonshare.messages.Async_rv
            }
            _g_local_namespace_locks[ns] = thread.allocate_lock()
            _g_async_rvs[ns] = {}
        else:
            raise ValueError('Unknown namespace "%s"' % (ns,))
    if init_code != None:
        if isinstance(init_code, basestring):
            try:
                exec init_code in _g_local_namespaces[ns]
            except Exception, e:
                daemon_log('namespace "%s" init error in <string>:\n%s\n\n%s' % (
                    ns, code2string(init_code), exception2string(sys.exc_info())))
        elif isinstance(init_code, dict):
            # Directly use the dictionary (locals() or globals(), for
            # instance) as a Pythonshare namespace.
            clean_ns = _g_local_namespaces[ns]
            _g_local_namespaces[ns] = init_code
            _g_local_namespaces[ns].update(clean_ns) # copy pythonshare defaults
        else:
            raise TypeError("unsupported init_code type")