I have a app that runs some *.exe program that returns a file (*.out) to be processed every couple of second. 
So if a user hits play button I create lls file put it in a directory, sets status in db to 11 and then after some calculation is done user clicks on stop button and lls file is deleted, status in db is set back to 10, and some more actions are done with out file (doesn't really matter)
if I run web2py as standalone so doble click on web2py.py file in my windows explorer the lls file is not deleted, BUT there is a catch. If I refresh the page, click the stop button in my webapp lls file is deleted
        path = os.path.join(request.folder, 'engine')
        llsPath = os.path.join(request.folder, 'engine', 'e1', 
request.vars.id + '.lls') 
        
        data = db(getDbScript(db(getDbScript(
request.vars.id)).select(
db.scripts.id, db.scripts.sc_lls, db.scripts.sc_engine_output, db.scripts.sc_status, db.scripts.sc_menu_data).first())).select(
db.scripts.id, db.scripts.sc_lls, db.scripts.sc_engine_output, db.scripts.sc_status, db.scripts.sc_menu_data).first()
        script = db(getDbScript(
request.vars.id)).select(
db.scripts.id, db.scripts.sc_lls, db.scripts.sc_engine_output, db.scripts.sc_status, db.scripts.sc_menu_data,db.scripts.sc_organization, db.scripts.sc_cal_start).first()
        org = script["sc_organization"]
        shifts = db(db.shifts.sh_organisation == org).select(db.shifts.sh_code, db.shifts.sh_start1,db.shifts.sh_start2,db.shifts.sh_end1,db.shifts.sh_end2,db.shifts.sh_color,db.shifts.sh_length1,db.shifts.sh_length2).as_list()
        outPath = os.path.join(request.folder, 'engine', 'e1', 
request.vars.id + '.out')
        
        if not script:
            return dict(status = -1)
        
        ###Status = 11 - Script is being  calculated 
        if script.sc_status == 11:
            
            
            # Change status - status = 10 --> user lahko da skripo računat - nima napak oz pomanjklivih podatkov
            # Add when user stopped calculation (ce bojo problemi se bo zraven posiljalo tudi id od script activitya)
            #Odstranim lls datoteko --> engine preneha delovat
            if os.path.isfile(llsPath):
                os.remove(llsPath)
            
            activity.update_record(sa_stop = 'now')
            script.update_record(sc_status = 10)
            
            
            ##če obstaja out datotkea
            if os.path.isfile(outPath):
                #preberemo fajl
                #Vnesemo podatke v tabelo script
                #odstranim out. datoteko
                os.remove(outPath)
                workersDb = db(db.workers.w_organisation == org).select(
db.workers.id, db.workers.w_nick_name).as_list()
                #sparsamo out datoteko da jo lahko damo v tabelo result
                dateStart =  script["sc_cal_start"]
                resultData = parseOut(out, dateStart, shifts, workersDb, org)
                #Pišemo rezultate v tabelo results
                resultsDbInsert(resultData["resultsDbData"], org, id)
            
                
            return dict(status = 1)
        
           
        else:
           
            ##prevedemo skripto v id.lls, prav tako zapišemo še v sc_lls
            #
            db.script_activity.insert(sa_id_script = 
request.vars.id, sa_start = 'now');
            
            ##validiramo json če ima kakršne koli napake idt.
            valJson = validateJson(script.sc_menu_data)
            if 1!=1 :#not valJson:
                #validacija ni uspela vrnemo error 300 
                return dict(status = 300)
            #$#nov json - z vsemi errorji zapiđšemo v sc_menu_data
            script.update_record(sc_menu_data = valJson["formJson"])
            #če obstajjo errorji pol konc
            if  1!=1:#valJson["errors"]:
                #skripta gre v status 91, kar pomen da je user ne more dat računat
                script.update_record(sc_status = 91)
                #print valJson["errors"]
                return dict(status = 200)
            
            else:
                script.update_record(sc_status = 11)
                if os.path.isfile(outPath):
                    os.remove(outPath)
                TranslateData(script.sc_menu_data, path, id, org)
                # Run woshi engine
                path_1 =  os.path.join(path, 'e1')
                os.chdir(path_1)
                #p = subprocess.Popen(['w_parameter.bat', id], shell=True, stdout = subprocess.PIPE)
                p = subprocess.Popen(['woshi_engine.exe', id], shell=True, stdout = subprocess.PIPE)
                return dict(status = 1)
           
    except Exception as e:
        script.update_record(sc_status = 10)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        
        print(exc_type, fname, exc_tb.tb_lineno)
        print e.__doc__
        print e.message
       
        return dict(status = 666)