private PyScope InitializeScope(Dictionary <string, object> Values, HashSet <AssemblyDeclaration> Assemblies)
        {
            PyScope ScriptScope;

            using (Py.GIL())
            {
                ScriptScope = Py.CreateScope();

                ScriptScope.Set("CheckAlive", new Func <bool>(CheckAlive));

                string execThreadAlive = "import clr\nimport sys\n" +
                                         "from System import *\n" +
                                         "from System.Collections.Generic import *\n" +
                                         "def isExecutionThreadAlive(frame, event, arg):\n" +
                                         "	if not CheckAlive():\n"+
                                         "		sys.exit()\n"+
                                         "	return isExecutionThreadAlive\n";

                ScriptScope.Exec(execThreadAlive);

                if (Values != null)
                {
                    foreach (string name in Values.Keys)
                    {
                        ScriptScope.Set(name, Values[name].ToPython());
                    }
                }

                if (Assemblies != null)
                {
                    foreach (AssemblyDeclaration ad in Assemblies)
                    {
                        ScriptScope.Exec("sys.path.append(r\"" + ad.Location + "\")\n" +
                                         "clr.AddReference(\"" + ad.Name + "\")\n");
                    }
                }

                ScriptScope.Exec("sys.settrace(isExecutionThreadAlive)\n");
            }

            return(ScriptScope);
        }