# initiated by the psrun.py script to be an independent run after which runScript terminatesrestarts again for the next run
        if cml_args.exitWhenDone:
            maxNumberOfConsecutiveRuns = 1
            allowRelaunch = False
    except:  # if for whatever reason we cannot do it we stay with the default value
        pass

    while (True):  # by default we are looping the simulation to make sure parameter scans are handled properly

        cc3dSimulationDataHandler = None

        from FileLock import FileLock

        with FileLock(file_name=fileName, timeout=10, delay=0.05)  as flock:

            CompuCellSetup.resetGlobals()
            CompuCellSetup.simulationPaths = CompuCellSetup.SimulationPaths()

            sim, simthread = CompuCellSetup.getCoreSimulationObjects(True)

            # import PlayerPython
            #
            # field_handler = simthread
            #
            # field_extractor_local = PlayerPython.FieldExtractor()
            # field_extractor_local.setFieldStorage(field_handler.fieldStorage)
            # field_extractor_local.init(sim)

            setSimulationResultStorageDirectory(
                cmlParser.customScreenshotDirectoryName)  # set Simulation output dir - it can be reset later - at this point only directory name is set. directory gets created later
        if cmlParser.exitWhenDone:
            maxNumberOfConsecutiveRuns = 1
            allowRelaunch = False
    except:  # if for whatever reason we cannot do it we stay with the default value
        pass

    while (
            True
    ):  # by default we are looping the simulation to make sure parameter scans are handled properly

        cc3dSimulationDataHandler = None

        from FileLock import FileLock
        with FileLock(file_name=fileName, timeout=10, delay=0.05) as flock:

            CompuCellSetup.resetGlobals()
            CompuCellSetup.simulationPaths = CompuCellSetup.SimulationPaths()

            sim, simthread = CompuCellSetup.getCoreSimulationObjects(True)

            setSimulationResultStorageDirectory(
                cmlParser.customScreenshotDirectoryName
            )  # set Simulation output dir - it can be reset later - at this point only directory name is set. directory gets created later

            CompuCellSetup.simulationFileName = fileName

            # print 'GOT HERE'
            if re.match(".*\.xml$", fileName):  # If filename ends with .xml
                print "GOT FILE ", fileName

                pythonScriptName = CompuCellSetup.ExtractPythonScriptNameFromXML(