import sys

#
# Spawned process.
#
# Set up our globals before running the target file.  
#
def ghs_process_launcher(ghs_dict, process_filename):
    try:
        globals().update(ghs_dict)

        startup_filename = __ghs_site_default_python_dir + '/ghs_startup.py'
        execfile(startup_filename, globals(), globals())
    except:
    	exception_info = sys.exc_info()
        print 'error: ', exception_info[0]
	print 'value: ', exception_info[1]
	print 'traceback: ', exception_info[2]

    global self_dbw
    self_dbw = winreg.GetDebuggerWindow()
    execfile(process_filename, globals(), globals())

#
# Create a new process that has access to the debugger.  This is useful on
# Windows, where the process created by multiprocessing.Process doesn't have
# access to the GHS objects.
#
# global_dict should be globals() and should include the __ghs global variables
# process_filename is the filename (with path) to be executed on the spawned process
#
def GHS_Process(global_dict, process_filename):
    from multiprocessing import Process
    # get all the global variables that start with __ghs
    ghs_dict = dict([(k, v) for k, v in global_dict.items() if k.startswith('__ghs')])

    p = Process(target=ghs_process_launcher, args=(ghs_dict, process_filename))
    return p;

